Commit d024044a authored by marja@chromium.org's avatar marja@chromium.org

Test cleanup: Using MockSpecialStoragePolicy instead of local subclasses of SpecialStoragePolicy.


BUG=NONE
TEST=Existing tests pass: FileSystemDirURLRequestJobTest.*, FileSystemURLRequestJobTest.*, FileSystemContextTest.*, DatabaseTrackerTest.*, QuotaFileUtilTest.*, FileSystemPathManagerTest.*, SandboxMountPointProviderMigrationTest.*


Review URL: http://codereview.chromium.org/7633016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97119 0039d316-1c4b-4281-b951-d872f2087c98
parent 4ace6177
...@@ -15,29 +15,14 @@ ...@@ -15,29 +15,14 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webkit/database/database_tracker.h" #include "webkit/database/database_tracker.h"
#include "webkit/database/database_util.h" #include "webkit/database/database_util.h"
#include "webkit/quota/mock_special_storage_policy.h"
#include "webkit/quota/quota_manager.h" #include "webkit/quota/quota_manager.h"
#include "webkit/quota/special_storage_policy.h"
namespace { namespace {
const char kOrigin1Url[] = "http://origin1"; const char kOrigin1Url[] = "http://origin1";
const char kOrigin2Url[] = "http://protected_origin2"; const char kOrigin2Url[] = "http://protected_origin2";
class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
public:
virtual bool IsStorageProtected(const GURL& origin) {
return origin == GURL(kOrigin2Url);
}
virtual bool IsStorageUnlimited(const GURL& origin) {
return false;
}
virtual bool IsFileHandler(const std::string& extension_id) {
return false;
}
};
class TestObserver : public webkit_database::DatabaseTracker::Observer { class TestObserver : public webkit_database::DatabaseTracker::Observer {
public: public:
TestObserver() : new_notification_received_(false) {} TestObserver() : new_notification_received_(false) {}
...@@ -185,10 +170,12 @@ class DatabaseTracker_TestHelper_Test { ...@@ -185,10 +170,12 @@ class DatabaseTracker_TestHelper_Test {
// Initialize the tracker database. // Initialize the tracker database.
ScopedTempDir temp_dir; ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddProtected(GURL(kOrigin2Url));
scoped_refptr<DatabaseTracker> tracker( scoped_refptr<DatabaseTracker> tracker(
new DatabaseTracker(temp_dir.path(), incognito_mode, false, new DatabaseTracker(temp_dir.path(), incognito_mode, false,
new TestSpecialStoragePolicy, special_storage_policy, NULL, NULL));
NULL, NULL));
// Create and open three databases. // Create and open three databases.
int64 database_size = 0; int64 database_size = 0;
...@@ -288,10 +275,12 @@ class DatabaseTracker_TestHelper_Test { ...@@ -288,10 +275,12 @@ class DatabaseTracker_TestHelper_Test {
// Initialize the tracker database. // Initialize the tracker database.
ScopedTempDir temp_dir; ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddProtected(GURL(kOrigin2Url));
scoped_refptr<DatabaseTracker> tracker( scoped_refptr<DatabaseTracker> tracker(
new DatabaseTracker(temp_dir.path(), incognito_mode, false, new DatabaseTracker(temp_dir.path(), incognito_mode, false,
new TestSpecialStoragePolicy, special_storage_policy, NULL, NULL));
NULL, NULL));
// Add two observers. // Add two observers.
TestObserver observer1; TestObserver observer1;
...@@ -535,11 +524,13 @@ class DatabaseTracker_TestHelper_Test { ...@@ -535,11 +524,13 @@ class DatabaseTracker_TestHelper_Test {
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath origin1_db_dir; FilePath origin1_db_dir;
{ {
scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddProtected(GURL(kOrigin2Url));
scoped_refptr<DatabaseTracker> tracker( scoped_refptr<DatabaseTracker> tracker(
new DatabaseTracker( new DatabaseTracker(
temp_dir.path(), false, true, temp_dir.path(), false, true,
new TestSpecialStoragePolicy, special_storage_policy, NULL,
NULL,
base::MessageLoopProxy::current())); base::MessageLoopProxy::current()));
// Open three new databases. // Open three new databases.
...@@ -596,10 +587,12 @@ class DatabaseTracker_TestHelper_Test { ...@@ -596,10 +587,12 @@ class DatabaseTracker_TestHelper_Test {
} }
// At this point, the database tracker should be gone. Create a new one. // At this point, the database tracker should be gone. Create a new one.
scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddProtected(GURL(kOrigin2Url));
scoped_refptr<DatabaseTracker> tracker( scoped_refptr<DatabaseTracker> tracker(
new DatabaseTracker(temp_dir.path(), false, false, new DatabaseTracker(temp_dir.path(), false, false,
new TestSpecialStoragePolicy, special_storage_policy, NULL, NULL));
NULL, NULL));
// Get all data for all origins. // Get all data for all origins.
std::vector<OriginInfo> origins_info; std::vector<OriginInfo> origins_info;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webkit/quota/mock_special_storage_policy.h"
#include "webkit/quota/quota_manager.h" #include "webkit/quota/quota_manager.h"
namespace fileapi { namespace fileapi {
...@@ -24,21 +25,6 @@ static const char* const kTestOrigins[] = { ...@@ -24,21 +25,6 @@ static const char* const kTestOrigins[] = {
"file:///", "file:///",
}; };
class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
public:
virtual bool IsStorageProtected(const GURL& origin) {
return false;
}
virtual bool IsStorageUnlimited(const GURL& origin) {
return origin == GURL(kTestOrigins[1]);
}
virtual bool IsFileHandler(const std::string& extension_id) {
return false;
}
};
scoped_refptr<FileSystemContext> NewFileSystemContext( scoped_refptr<FileSystemContext> NewFileSystemContext(
bool allow_file_access, bool allow_file_access,
bool unlimited_quota, bool unlimited_quota,
...@@ -81,7 +67,10 @@ TEST(FileSystemContextTest, IsStorageUnlimited) { ...@@ -81,7 +67,10 @@ TEST(FileSystemContextTest, IsStorageUnlimited) {
} }
// With SpecialStoragePolicy. // With SpecialStoragePolicy.
scoped_refptr<TestSpecialStoragePolicy> policy(new TestSpecialStoragePolicy); scoped_refptr<quota::MockSpecialStoragePolicy> policy(
new quota::MockSpecialStoragePolicy);
policy->AddUnlimited(GURL(kTestOrigins[1]));
context = NewFileSystemContext(false, false, policy); context = NewFileSystemContext(false, false, policy);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w policy #" SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w policy #"
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h" #include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi { namespace fileapi {
namespace { namespace {
...@@ -41,21 +42,6 @@ namespace { ...@@ -41,21 +42,6 @@ namespace {
static const char kFileSystemURLPrefix[] = static const char kFileSystemURLPrefix[] =
"filesystem:http://remote/temporary/"; "filesystem:http://remote/temporary/";
class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
public:
virtual bool IsStorageProtected(const GURL& origin) {
return false;
}
virtual bool IsStorageUnlimited(const GURL& origin) {
return true;
}
virtual bool IsFileHandler(const std::string& extension_id) {
return true;
}
};
} // namespace } // namespace
class FileSystemDirURLRequestJobTest : public testing::Test { class FileSystemDirURLRequestJobTest : public testing::Test {
...@@ -70,7 +56,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test { ...@@ -70,7 +56,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
file_thread_proxy_ = base::MessageLoopProxy::current(); file_thread_proxy_ = base::MessageLoopProxy::current();
special_storage_policy_ = new TestSpecialStoragePolicy(); special_storage_policy_ = new quota::MockSpecialStoragePolicy;
file_system_context_ = file_system_context_ =
new FileSystemContext( new FileSystemContext(
base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
...@@ -230,7 +216,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test { ...@@ -230,7 +216,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
FilePath root_path_; FilePath root_path_;
scoped_ptr<net::URLRequest> request_; scoped_ptr<net::URLRequest> request_;
scoped_ptr<TestDelegate> delegate_; scoped_ptr<TestDelegate> delegate_;
scoped_refptr<TestSpecialStoragePolicy> special_storage_policy_; scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_;
scoped_refptr<FileSystemContext> file_system_context_; scoped_refptr<FileSystemContext> file_system_context_;
base::ScopedCallbackFactory<FileSystemDirURLRequestJobTest> callback_factory_; base::ScopedCallbackFactory<FileSystemDirURLRequestJobTest> callback_factory_;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/special_storage_policy.h" #include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi { namespace fileapi {
namespace { namespace {
...@@ -205,21 +205,6 @@ FilePath UTF8ToFilePath(const std::string& str) { ...@@ -205,21 +205,6 @@ FilePath UTF8ToFilePath(const std::string& str) {
return FilePath(result); return FilePath(result);
} }
class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
public:
virtual bool IsStorageProtected(const GURL& origin) {
return false;
}
virtual bool IsStorageUnlimited(const GURL& origin) {
return true;
}
virtual bool IsFileHandler(const std::string& extension_id) {
return true;
}
};
} // namespace } // namespace
class FileSystemPathManagerTest : public testing::Test { class FileSystemPathManagerTest : public testing::Test {
...@@ -243,7 +228,7 @@ class FileSystemPathManagerTest : public testing::Test { ...@@ -243,7 +228,7 @@ class FileSystemPathManagerTest : public testing::Test {
base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
data_dir_.path(), data_dir_.path(),
scoped_refptr<quota::SpecialStoragePolicy>( scoped_refptr<quota::SpecialStoragePolicy>(
new TestSpecialStoragePolicy()), new quota::MockSpecialStoragePolicy),
incognito, incognito,
allow_file_access); allow_file_access);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
...@@ -14,33 +14,9 @@ ...@@ -14,33 +14,9 @@
#include "webkit/fileapi/file_system_usage_cache.h" #include "webkit/fileapi/file_system_usage_cache.h"
#include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/special_storage_policy.h" #include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi { namespace fileapi {
namespace {
class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
public:
explicit 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( FileSystemTestOriginHelper::FileSystemTestOriginHelper(
const GURL& origin, FileSystemType type) const GURL& origin, FileSystemType type)
...@@ -93,10 +69,13 @@ void FileSystemTestOriginHelper::SetUp( ...@@ -93,10 +69,13 @@ void FileSystemTestOriginHelper::SetUp(
FileSystemFileUtil* file_util) { FileSystemFileUtil* file_util) {
file_util_ = file_util; file_util_ = file_util;
DCHECK(file_util_); DCHECK(file_util_);
scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
new quota::MockSpecialStoragePolicy;
special_storage_policy->SetAllUnlimited(unlimited_quota);
file_system_context_ = new FileSystemContext( file_system_context_ = new FileSystemContext(
base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
new TestSpecialStoragePolicy(unlimited_quota), special_storage_policy,
quota_manager_proxy, quota_manager_proxy,
base_dir, base_dir,
incognito_mode, incognito_mode,
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h" #include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi { namespace fileapi {
namespace { namespace {
...@@ -60,21 +61,6 @@ void FillBuffer(char* buffer, size_t len) { ...@@ -60,21 +61,6 @@ void FillBuffer(char* buffer, size_t len) {
} }
} }
class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
public:
virtual bool IsStorageProtected(const GURL& origin) {
return false;
}
virtual bool IsStorageUnlimited(const GURL& origin) {
return true;
}
virtual bool IsFileHandler(const std::string& extension_id) {
return true;
}
};
} // namespace } // namespace
class FileSystemURLRequestJobTest : public testing::Test { class FileSystemURLRequestJobTest : public testing::Test {
...@@ -87,7 +73,7 @@ class FileSystemURLRequestJobTest : public testing::Test { ...@@ -87,7 +73,7 @@ class FileSystemURLRequestJobTest : public testing::Test {
virtual void SetUp() { virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
special_storage_policy_ = new TestSpecialStoragePolicy(); special_storage_policy_ = new quota::MockSpecialStoragePolicy;
// We use the main thread so that we can get the root path synchronously. // We use the main thread so that we can get the root path synchronously.
// TODO(adamk): Run this on the FILE thread we've created as well. // TODO(adamk): Run this on the FILE thread we've created as well.
file_system_context_ = file_system_context_ =
...@@ -216,7 +202,7 @@ class FileSystemURLRequestJobTest : public testing::Test { ...@@ -216,7 +202,7 @@ class FileSystemURLRequestJobTest : public testing::Test {
ScopedTempDir temp_dir_; ScopedTempDir temp_dir_;
FilePath origin_root_path_; FilePath origin_root_path_;
scoped_refptr<TestSpecialStoragePolicy> special_storage_policy_; scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_;
scoped_refptr<FileSystemContext> file_system_context_; scoped_refptr<FileSystemContext> file_system_context_;
base::ScopedCallbackFactory<FileSystemURLRequestJobTest> callback_factory_; base::ScopedCallbackFactory<FileSystemURLRequestJobTest> callback_factory_;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h" #include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/file_system_util.h"
#include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi { namespace fileapi {
...@@ -127,27 +128,6 @@ const MigrationTestCaseRecord kMigrationTestRecords[] = { ...@@ -127,27 +128,6 @@ const MigrationTestCaseRecord kMigrationTestRecords[] = {
{ GURL("file:///"), false, true }, { GURL("file:///"), false, true },
}; };
class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
public:
explicit 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 } // anonymous namespace
class SandboxMountPointProviderMigrationTest : public testing::Test { class SandboxMountPointProviderMigrationTest : public testing::Test {
...@@ -160,10 +140,13 @@ class SandboxMountPointProviderMigrationTest : public testing::Test { ...@@ -160,10 +140,13 @@ class SandboxMountPointProviderMigrationTest : public testing::Test {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
path_manager_ = new MockFileSystemPathManager(data_dir_.path()); path_manager_ = new MockFileSystemPathManager(data_dir_.path());
scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
new quota::MockSpecialStoragePolicy;
special_storage_policy->SetAllUnlimited(true);
file_system_context_ = new FileSystemContext( file_system_context_ = new FileSystemContext(
base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
new TestSpecialStoragePolicy(true /* unlimited quota */), special_storage_policy,
NULL, NULL,
data_dir_.path(), data_dir_.path(),
false, // incognito false, // incognito
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
namespace quota { namespace quota {
MockSpecialStoragePolicy::MockSpecialStoragePolicy() {} MockSpecialStoragePolicy::MockSpecialStoragePolicy()
: all_unlimited_(false) {}
MockSpecialStoragePolicy::~MockSpecialStoragePolicy() {} MockSpecialStoragePolicy::~MockSpecialStoragePolicy() {}
bool MockSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { bool MockSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
...@@ -14,6 +16,8 @@ bool MockSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { ...@@ -14,6 +16,8 @@ bool MockSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
} }
bool MockSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { bool MockSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) {
if (all_unlimited_)
return true;
return unlimited_.find(origin) != unlimited_.end(); return unlimited_.find(origin) != unlimited_.end();
} }
......
...@@ -33,6 +33,10 @@ class MockSpecialStoragePolicy : public quota::SpecialStoragePolicy { ...@@ -33,6 +33,10 @@ class MockSpecialStoragePolicy : public quota::SpecialStoragePolicy {
file_handlers_.insert(id); file_handlers_.insert(id);
} }
void SetAllUnlimited(bool all_unlimited) {
all_unlimited_ = all_unlimited;
}
void Reset() { void Reset() {
protected_.clear(); protected_.clear();
unlimited_.clear(); unlimited_.clear();
...@@ -47,6 +51,8 @@ class MockSpecialStoragePolicy : public quota::SpecialStoragePolicy { ...@@ -47,6 +51,8 @@ class MockSpecialStoragePolicy : public quota::SpecialStoragePolicy {
std::set<GURL> protected_; std::set<GURL> protected_;
std::set<GURL> unlimited_; std::set<GURL> unlimited_;
std::set<std::string> file_handlers_; std::set<std::string> file_handlers_;
bool all_unlimited_;
}; };
} // namespace quota } // namespace quota
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment