summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-17 09:23:00 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-17 09:23:00 +0000
commitd024044a7b26967f7db9d9b228224a98cb7c159d (patch)
treeb34e31150a8628e252e1c9f4cbcdd88197e752ca
parent4ace61778d6bfa9eb8a61f5a1879ba1bb278a561 (diff)
downloadchromium_src-d024044a7b26967f7db9d9b228224a98cb7c159d.zip
chromium_src-d024044a7b26967f7db9d9b228224a98cb7c159d.tar.gz
chromium_src-d024044a7b26967f7db9d9b228224a98cb7c159d.tar.bz2
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
-rw-r--r--webkit/database/database_tracker_unittest.cc41
-rw-r--r--webkit/fileapi/file_system_context_unittest.cc21
-rw-r--r--webkit/fileapi/file_system_dir_url_request_job_unittest.cc20
-rw-r--r--webkit/fileapi/file_system_path_manager_unittest.cc19
-rw-r--r--webkit/fileapi/file_system_test_helper.cc31
-rw-r--r--webkit/fileapi/file_system_url_request_job_unittest.cc20
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider_unittest.cc27
-rw-r--r--webkit/quota/mock_special_storage_policy.cc6
-rw-r--r--webkit/quota/mock_special_storage_policy.h6
9 files changed, 51 insertions, 140 deletions
diff --git a/webkit/database/database_tracker_unittest.cc b/webkit/database/database_tracker_unittest.cc
index cf499b9..9080933 100644
--- a/webkit/database/database_tracker_unittest.cc
+++ b/webkit/database/database_tracker_unittest.cc
@@ -15,29 +15,14 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/database/database_tracker.h"
#include "webkit/database/database_util.h"
+#include "webkit/quota/mock_special_storage_policy.h"
#include "webkit/quota/quota_manager.h"
-#include "webkit/quota/special_storage_policy.h"
namespace {
const char kOrigin1Url[] = "http://origin1";
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 {
public:
TestObserver() : new_notification_received_(false) {}
@@ -185,10 +170,12 @@ class DatabaseTracker_TestHelper_Test {
// Initialize the tracker database.
ScopedTempDir temp_dir;
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(
new DatabaseTracker(temp_dir.path(), incognito_mode, false,
- new TestSpecialStoragePolicy,
- NULL, NULL));
+ special_storage_policy, NULL, NULL));
// Create and open three databases.
int64 database_size = 0;
@@ -288,10 +275,12 @@ class DatabaseTracker_TestHelper_Test {
// Initialize the tracker database.
ScopedTempDir temp_dir;
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(
new DatabaseTracker(temp_dir.path(), incognito_mode, false,
- new TestSpecialStoragePolicy,
- NULL, NULL));
+ special_storage_policy, NULL, NULL));
// Add two observers.
TestObserver observer1;
@@ -535,11 +524,13 @@ class DatabaseTracker_TestHelper_Test {
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath origin1_db_dir;
{
+ scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
+ new quota::MockSpecialStoragePolicy;
+ special_storage_policy->AddProtected(GURL(kOrigin2Url));
scoped_refptr<DatabaseTracker> tracker(
new DatabaseTracker(
temp_dir.path(), false, true,
- new TestSpecialStoragePolicy,
- NULL,
+ special_storage_policy, NULL,
base::MessageLoopProxy::current()));
// Open three new databases.
@@ -596,10 +587,12 @@ class DatabaseTracker_TestHelper_Test {
}
// 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(
new DatabaseTracker(temp_dir.path(), false, false,
- new TestSpecialStoragePolicy,
- NULL, NULL));
+ special_storage_policy, NULL, NULL));
// Get all data for all origins.
std::vector<OriginInfo> origins_info;
diff --git a/webkit/fileapi/file_system_context_unittest.cc b/webkit/fileapi/file_system_context_unittest.cc
index 2992dfb..19da157 100644
--- a/webkit/fileapi/file_system_context_unittest.cc
+++ b/webkit/fileapi/file_system_context_unittest.cc
@@ -12,6 +12,7 @@
#include "base/string_number_conversions.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/quota/mock_special_storage_policy.h"
#include "webkit/quota/quota_manager.h"
namespace fileapi {
@@ -24,21 +25,6 @@ static const char* const kTestOrigins[] = {
"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(
bool allow_file_access,
bool unlimited_quota,
@@ -81,7 +67,10 @@ TEST(FileSystemContextTest, IsStorageUnlimited) {
}
// 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);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w policy #"
diff --git a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
index 6865957..8a1116e5 100644
--- a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
+++ b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
@@ -33,6 +33,7 @@
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
+#include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi {
namespace {
@@ -41,21 +42,6 @@ namespace {
static const char kFileSystemURLPrefix[] =
"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
class FileSystemDirURLRequestJobTest : public testing::Test {
@@ -70,7 +56,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
file_thread_proxy_ = base::MessageLoopProxy::current();
- special_storage_policy_ = new TestSpecialStoragePolicy();
+ special_storage_policy_ = new quota::MockSpecialStoragePolicy;
file_system_context_ =
new FileSystemContext(
base::MessageLoopProxy::current(),
@@ -230,7 +216,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
FilePath root_path_;
scoped_ptr<net::URLRequest> request_;
scoped_ptr<TestDelegate> delegate_;
- scoped_refptr<TestSpecialStoragePolicy> special_storage_policy_;
+ scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_;
scoped_refptr<FileSystemContext> file_system_context_;
base::ScopedCallbackFactory<FileSystemDirURLRequestJobTest> callback_factory_;
diff --git a/webkit/fileapi/file_system_path_manager_unittest.cc b/webkit/fileapi/file_system_path_manager_unittest.cc
index 008c077..afa157b 100644
--- a/webkit/fileapi/file_system_path_manager_unittest.cc
+++ b/webkit/fileapi/file_system_path_manager_unittest.cc
@@ -21,7 +21,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_util.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 {
@@ -205,21 +205,6 @@ FilePath UTF8ToFilePath(const std::string& str) {
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
class FileSystemPathManagerTest : public testing::Test {
@@ -243,7 +228,7 @@ class FileSystemPathManagerTest : public testing::Test {
base::MessageLoopProxy::current(),
data_dir_.path(),
scoped_refptr<quota::SpecialStoragePolicy>(
- new TestSpecialStoragePolicy()),
+ new quota::MockSpecialStoragePolicy),
incognito,
allow_file_access);
#if defined(OS_CHROMEOS)
diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc
index 535ad76..3748f86 100644
--- a/webkit/fileapi/file_system_test_helper.cc
+++ b/webkit/fileapi/file_system_test_helper.cc
@@ -14,33 +14,9 @@
#include "webkit/fileapi/file_system_usage_cache.h"
#include "webkit/fileapi/file_system_util.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 {
-
-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(
const GURL& origin, FileSystemType type)
@@ -93,10 +69,13 @@ void FileSystemTestOriginHelper::SetUp(
FileSystemFileUtil* file_util) {
file_util_ = 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(
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
- new TestSpecialStoragePolicy(unlimited_quota),
+ special_storage_policy,
quota_manager_proxy,
base_dir,
incognito_mode,
diff --git a/webkit/fileapi/file_system_url_request_job_unittest.cc b/webkit/fileapi/file_system_url_request_job_unittest.cc
index 61eee22..3b7cbc7 100644
--- a/webkit/fileapi/file_system_url_request_job_unittest.cc
+++ b/webkit/fileapi/file_system_url_request_job_unittest.cc
@@ -37,6 +37,7 @@
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
+#include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi {
namespace {
@@ -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
class FileSystemURLRequestJobTest : public testing::Test {
@@ -87,7 +73,7 @@ class FileSystemURLRequestJobTest : public testing::Test {
virtual void SetUp() {
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.
// TODO(adamk): Run this on the FILE thread we've created as well.
file_system_context_ =
@@ -216,7 +202,7 @@ class FileSystemURLRequestJobTest : public testing::Test {
ScopedTempDir temp_dir_;
FilePath origin_root_path_;
- scoped_refptr<TestSpecialStoragePolicy> special_storage_policy_;
+ scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_;
scoped_refptr<FileSystemContext> file_system_context_;
base::ScopedCallbackFactory<FileSystemURLRequestJobTest> callback_factory_;
diff --git a/webkit/fileapi/sandbox_mount_point_provider_unittest.cc b/webkit/fileapi/sandbox_mount_point_provider_unittest.cc
index d41d46b..53d94a8 100644
--- a/webkit/fileapi/sandbox_mount_point_provider_unittest.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider_unittest.cc
@@ -22,6 +22,7 @@
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_util.h"
+#include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi {
@@ -127,27 +128,6 @@ const MigrationTestCaseRecord kMigrationTestRecords[] = {
{ 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
class SandboxMountPointProviderMigrationTest : public testing::Test {
@@ -160,10 +140,13 @@ class SandboxMountPointProviderMigrationTest : public testing::Test {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
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(
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
- new TestSpecialStoragePolicy(true /* unlimited quota */),
+ special_storage_policy,
NULL,
data_dir_.path(),
false, // incognito
diff --git a/webkit/quota/mock_special_storage_policy.cc b/webkit/quota/mock_special_storage_policy.cc
index 0de3dd0..8b75073 100644
--- a/webkit/quota/mock_special_storage_policy.cc
+++ b/webkit/quota/mock_special_storage_policy.cc
@@ -6,7 +6,9 @@
namespace quota {
-MockSpecialStoragePolicy::MockSpecialStoragePolicy() {}
+MockSpecialStoragePolicy::MockSpecialStoragePolicy()
+ : all_unlimited_(false) {}
+
MockSpecialStoragePolicy::~MockSpecialStoragePolicy() {}
bool MockSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
@@ -14,6 +16,8 @@ bool MockSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
}
bool MockSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) {
+ if (all_unlimited_)
+ return true;
return unlimited_.find(origin) != unlimited_.end();
}
diff --git a/webkit/quota/mock_special_storage_policy.h b/webkit/quota/mock_special_storage_policy.h
index 3f3a873..b04d16d 100644
--- a/webkit/quota/mock_special_storage_policy.h
+++ b/webkit/quota/mock_special_storage_policy.h
@@ -33,6 +33,10 @@ class MockSpecialStoragePolicy : public quota::SpecialStoragePolicy {
file_handlers_.insert(id);
}
+ void SetAllUnlimited(bool all_unlimited) {
+ all_unlimited_ = all_unlimited;
+ }
+
void Reset() {
protected_.clear();
unlimited_.clear();
@@ -47,6 +51,8 @@ class MockSpecialStoragePolicy : public quota::SpecialStoragePolicy {
std::set<GURL> protected_;
std::set<GURL> unlimited_;
std::set<std::string> file_handlers_;
+
+ bool all_unlimited_;
};
} // namespace quota