summaryrefslogtreecommitdiffstats
path: root/webkit/quota
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 03:20:11 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 03:20:11 +0000
commit52ba8b6171dfae6e1d744972d515a35d878a59c3 (patch)
tree64ddecb94f5bd219ee925f8faf5717c0fdd75991 /webkit/quota
parent506cddf4e9887fb8e57ab8f8a00b2dd1cbcc6411 (diff)
downloadchromium_src-52ba8b6171dfae6e1d744972d515a35d878a59c3.zip
chromium_src-52ba8b6171dfae6e1d744972d515a35d878a59c3.tar.gz
chromium_src-52ba8b6171dfae6e1d744972d515a35d878a59c3.tar.bz2
Add QM::NotifyStorageAccessedInternal which takes time parameter
We need to be able to explicitly specify 'last_access_time' so that test works on all the platforms (namely on Windows). BUG=83805 TEST=QuotaManager.{NotifyAndLRUOrigin,GetLRUOriginWithOriginInUse} Review URL: http://codereview.chromium.org/7167010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota')
-rw-r--r--webkit/quota/quota_manager.cc117
-rw-r--r--webkit/quota/quota_manager.h9
-rw-r--r--webkit/quota/quota_manager_unittest.cc498
3 files changed, 305 insertions, 319 deletions
diff --git a/webkit/quota/quota_manager.cc b/webkit/quota/quota_manager.cc
index 0688ec0..52cd4eb 100644
--- a/webkit/quota/quota_manager.cc
+++ b/webkit/quota/quota_manager.cc
@@ -17,6 +17,7 @@
#include "base/stl_util-inl.h"
#include "base/string_number_conversions.h"
#include "base/sys_info.h"
+#include "base/time.h"
#include "net/base/net_util.h"
#include "webkit/quota/quota_database.h"
#include "webkit/quota/quota_temporary_storage_evictor.h"
@@ -346,13 +347,10 @@ QuotaManager::UsageAndQuotaDispatcherTask::Create(
class QuotaManager::DatabaseTaskBase : public QuotaThreadTask {
public:
- DatabaseTaskBase(
- QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop)
- : QuotaThreadTask(manager, db_message_loop),
+ DatabaseTaskBase(QuotaManager* manager)
+ : QuotaThreadTask(manager, manager->db_thread_),
manager_(manager),
- database_(database),
+ database_(manager->database_.get()),
db_disabled_(false) {
DCHECK(manager_);
DCHECK(database_);
@@ -384,11 +382,9 @@ class QuotaManager::InitializeTask : public QuotaManager::DatabaseTaskBase {
public:
InitializeTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
const FilePath& profile_path,
bool is_incognito)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
profile_path_(profile_path),
is_incognito_(is_incognito),
need_initialize_origins_(false),
@@ -430,11 +426,9 @@ class QuotaManager::TemporaryGlobalQuotaUpdateTask
public:
TemporaryGlobalQuotaUpdateTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
int64 new_quota,
QuotaCallback* callback)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
new_quota_(new_quota),
callback_(callback) {
DCHECK_GE(new_quota, 0);
@@ -466,11 +460,9 @@ class QuotaManager::PersistentHostQuotaQueryTask
public:
PersistentHostQuotaQueryTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
const std::string& host,
HostQuotaCallback* callback)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
host_(host),
quota_(-1),
callback_(callback) {
@@ -495,12 +487,10 @@ class QuotaManager::PersistentHostQuotaUpdateTask
public:
PersistentHostQuotaUpdateTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
const std::string& host,
int new_quota,
HostQuotaCallback* callback)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
host_(host),
new_quota_(new_quota),
callback_(callback) {
@@ -534,13 +524,11 @@ class QuotaManager::GetLRUOriginTask
public:
GetLRUOriginTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
StorageType type,
const std::map<GURL, int>& origins_in_use,
const std::map<GURL, int>& origins_in_error,
GetLRUOriginCallback *callback)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
type_(type),
callback_(callback),
special_storage_policy_(manager->special_storage_policy_) {
@@ -586,11 +574,9 @@ class QuotaManager::OriginDeletionDatabaseTask
public:
OriginDeletionDatabaseTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
const GURL& origin,
StorageType type)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
origin_(origin),
type_(type) {}
@@ -612,10 +598,8 @@ class QuotaManager::TemporaryOriginsRegistrationTask
public:
TemporaryOriginsRegistrationTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
UsageTracker* temporary_usage_tracker)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
has_registered_origins_(false) {
DCHECK(temporary_usage_tracker);
temporary_usage_tracker->GetCachedOrigins(&origins_);
@@ -682,18 +666,17 @@ class QuotaManager::OriginAccessRecordDatabaseTask
public:
OriginAccessRecordDatabaseTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
const GURL& origin,
- StorageType type)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ StorageType type,
+ base::Time accessed_time)
+ : DatabaseTaskBase(manager),
origin_(origin),
- type_(type) {}
+ type_(type),
+ accessed_time_(accessed_time) {}
protected:
virtual void RunOnTargetThread() OVERRIDE {
- if (!database()->SetOriginLastAccessTime(
- origin_, type_, base::Time::Now())) {
+ if (!database()->SetOriginLastAccessTime(origin_, type_, accessed_time_)) {
set_db_disabled(true);
}
}
@@ -702,6 +685,7 @@ class QuotaManager::OriginAccessRecordDatabaseTask
private:
GURL origin_;
StorageType type_;
+ base::Time accessed_time_;
};
class QuotaManager::DumpQuotaTableTask
@@ -716,10 +700,8 @@ class QuotaManager::DumpQuotaTableTask
public:
DumpQuotaTableTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
Callback* callback)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
callback_(callback) {
}
protected:
@@ -760,10 +742,8 @@ class QuotaManager::DumpLastAccessTimeTableTask
public:
DumpLastAccessTimeTableTask(
QuotaManager* manager,
- QuotaDatabase* database,
- scoped_refptr<base::MessageLoopProxy> db_message_loop,
Callback* callback)
- : DatabaseTaskBase(manager, database, db_message_loop),
+ : DatabaseTaskBase(manager),
callback_(callback) {
}
protected:
@@ -881,8 +861,7 @@ void QuotaManager::SetTemporaryGlobalQuota(int64 new_quota,
if (!db_disabled_) {
scoped_refptr<TemporaryGlobalQuotaUpdateTask> task(
- new TemporaryGlobalQuotaUpdateTask(
- this, database_.get(), db_thread_, new_quota, callback));
+ new TemporaryGlobalQuotaUpdateTask(this, new_quota, callback));
task->Start();
} else {
callback->Run(kQuotaErrorInvalidAccess,
@@ -903,8 +882,7 @@ void QuotaManager::GetPersistentHostQuota(const std::string& host,
return;
}
scoped_refptr<PersistentHostQuotaQueryTask> task(
- new PersistentHostQuotaQueryTask(
- this, database_.get(), db_thread_, host, callback.release()));
+ new PersistentHostQuotaQueryTask(this, host, callback.release()));
task->Start();
}
@@ -927,8 +905,7 @@ void QuotaManager::SetPersistentHostQuota(const std::string& host,
if (!db_disabled_) {
scoped_refptr<PersistentHostQuotaUpdateTask> task(
new PersistentHostQuotaUpdateTask(
- this, database_.get(), db_thread_, host, new_quota,
- callback.release()));
+ this, host, new_quota, callback.release()));
task->Start();
} else {
callback->Run(kQuotaErrorInvalidAccess,
@@ -981,8 +958,7 @@ void QuotaManager::LazyInitialize() {
special_storage_policy_));
scoped_refptr<InitializeTask> task(
- new InitializeTask(this, database_.get(), db_thread_,
- profile_path_, is_incognito_));
+ new InitializeTask(this, profile_path_, is_incognito_));
task->Start();
}
@@ -995,19 +971,7 @@ void QuotaManager::RegisterClient(QuotaClient* client) {
void QuotaManager::NotifyStorageAccessed(
QuotaClient::ID client_id,
const GURL& origin, StorageType type) {
- LazyInitialize();
- if (type == kStorageTypeTemporary && lru_origin_callback_.get()) {
- // Record the accessed origins while GetLRUOrigin task is runing
- // to filter out them from eviction.
- access_notified_origins_.insert(origin);
- }
-
- if (db_disabled_)
- return;
- scoped_refptr<OriginAccessRecordDatabaseTask> task(
- new OriginAccessRecordDatabaseTask(
- this, database_.get(), db_thread_, origin, type));
- task->Start();
+ NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now());
}
void QuotaManager::NotifyStorageModified(
@@ -1060,15 +1024,31 @@ void QuotaManager::GetCachedOrigins(
}
}
+void QuotaManager::NotifyStorageAccessedInternal(
+ QuotaClient::ID client_id,
+ const GURL& origin, StorageType type,
+ base::Time accessed_time) {
+ LazyInitialize();
+ if (type == kStorageTypeTemporary && lru_origin_callback_.get()) {
+ // Record the accessed origins while GetLRUOrigin task is runing
+ // to filter out them from eviction.
+ access_notified_origins_.insert(origin);
+ }
+
+ if (db_disabled_)
+ return;
+ scoped_refptr<OriginAccessRecordDatabaseTask> task(
+ new OriginAccessRecordDatabaseTask(this, origin, type, accessed_time));
+ task->Start();
+}
+
void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) {
- make_scoped_refptr(new DumpQuotaTableTask(
- this, database_.get(), db_thread_.get(), callback))->Start();
+ make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start();
}
void QuotaManager::DumpLastAccessTimeTable(
DumpLastAccessTimeTableCallback* callback) {
- make_scoped_refptr(new DumpLastAccessTimeTableTask(
- this, database_.get(), db_thread_.get(), callback))->Start();
+ make_scoped_refptr(new DumpLastAccessTimeTableTask(this, callback))->Start();
}
@@ -1078,8 +1058,7 @@ void QuotaManager::DeleteOriginFromDatabase(
if (db_disabled_)
return;
scoped_refptr<OriginDeletionDatabaseTask> task =
- new OriginDeletionDatabaseTask(
- this, database_.get(), db_thread_, origin, type);
+ new OriginDeletionDatabaseTask(this, origin, type);
task->Start();
}
@@ -1096,7 +1075,7 @@ void QuotaManager::GetLRUOrigin(
return;
}
scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask(
- this, database_.get(), db_thread_, type, origins_in_use_,
+ this, type, origins_in_use_,
origins_in_error_, callback_factory_.NewCallback(
&QuotaManager::DidGetDatabaseLRUOrigin)));
task->Start();
@@ -1247,7 +1226,7 @@ void QuotaManager::DidRunInitialGetTemporaryGlobalUsage(
// is completed.
scoped_refptr<TemporaryOriginsRegistrationTask> task(
new TemporaryOriginsRegistrationTask(
- this, database_.get(), db_thread_, temporary_usage_tracker_.get()));
+ this, temporary_usage_tracker_.get()));
task->Start();
}
diff --git a/webkit/quota/quota_manager.h b/webkit/quota/quota_manager.h
index 923cad7..beca602 100644
--- a/webkit/quota/quota_manager.h
+++ b/webkit/quota/quota_manager.h
@@ -102,7 +102,7 @@ class QuotaManager : public QuotaTaskObserver,
// Used to maintain LRU ordering.
void NotifyStorageAccessed(QuotaClient::ID client_id,
const GURL& origin,
- StorageType typea);
+ StorageType type);
// Called by clients via proxy.
// Client storage must call this method whenever they have made any
@@ -236,6 +236,13 @@ class QuotaManager : public QuotaTaskObserver,
// (Might return empty list if no origin is tracked by the tracker.)
void GetCachedOrigins(StorageType type, std::set<GURL>* origins);
+ // This internal method is separately defined mainly for testing.
+ void NotifyStorageAccessedInternal(
+ QuotaClient::ID client_id,
+ const GURL& origin,
+ StorageType type,
+ base::Time accessed_time);
+
void DumpQuotaTable(DumpQuotaTableCallback* callback);
void DumpLastAccessTimeTable(DumpLastAccessTimeTableCallback* callback);
diff --git a/webkit/quota/quota_manager_unittest.cc b/webkit/quota/quota_manager_unittest.cc
index db9b960..92b69896 100644
--- a/webkit/quota/quota_manager_unittest.cc
+++ b/webkit/quota/quota_manager_unittest.cc
@@ -13,6 +13,7 @@
#include "base/scoped_temp_dir.h"
#include "base/stl_util-inl.h"
#include "base/sys_info.h"
+#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h"
@@ -28,6 +29,10 @@ using WebKit::WebStorageQuotaType;
namespace quota {
+// For shorter names.
+const StorageType kTemp = kStorageTypeTemporary;
+const StorageType kPerm = kStorageTypePersistent;
+
class QuotaManagerTest : public testing::Test {
protected:
typedef QuotaManager::QuotaTableEntry QuotaTableEntry;
@@ -37,7 +42,8 @@ class QuotaManagerTest : public testing::Test {
public:
QuotaManagerTest()
- : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ virtual_time_counter_(0) {
}
void SetUp() {
@@ -187,7 +193,8 @@ class QuotaManagerTest : public testing::Test {
const GURL& origin,
StorageType type) {
DCHECK(client);
- quota_manager_->NotifyStorageAccessed(client->id(), origin, type);
+ quota_manager_->NotifyStorageAccessedInternal(
+ client->id(), origin, type, GetCurrentMockTime());
}
void DeleteOriginFromDatabase(const GURL& origin, StorageType type) {
@@ -328,6 +335,11 @@ class QuotaManagerTest : public testing::Test {
FilePath profile_path() const { return data_dir_.path(); }
private:
+ base::Time GetCurrentMockTime() {
+ ++virtual_time_counter_;
+ return base::Time::FromDoubleT(virtual_time_counter_ * 10.0);
+ }
+
ScopedTempDir data_dir_;
base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_;
@@ -347,23 +359,25 @@ class QuotaManagerTest : public testing::Test {
int additional_callback_count_;
+ int virtual_time_counter_;
+
DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest);
};
TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypeTemporary, 10 },
- { "http://foo.com/", kStorageTypePersistent, 80 },
+ { "http://foo.com/", kTemp, 10 },
+ { "http://foo.com/", kPerm, 80 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(80, usage());
EXPECT_EQ(0, quota());
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10, usage());
@@ -371,7 +385,7 @@ TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) {
EXPECT_GE(QuotaManager::kTemporaryStorageQuotaMaxSize, quota());
int64 quota_returned_for_foo = quota();
- GetUsageAndQuota(GURL("http://bar.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://bar.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(0, usage());
@@ -379,30 +393,30 @@ TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) {
}
TEST_F(QuotaManagerTest, GetUsage_NoClient) {
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(0, usage());
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(0, usage());
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
EXPECT_EQ(0, unlimited_usage());
- GetGlobalUsage(kStorageTypePersistent);
+ GetGlobalUsage(kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
EXPECT_EQ(0, unlimited_usage());
@@ -410,30 +424,30 @@ TEST_F(QuotaManagerTest, GetUsage_NoClient) {
TEST_F(QuotaManagerTest, GetUsage_EmptyClient) {
RegisterClient(CreateClient(NULL, 0));
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(0, usage());
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(0, usage());
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
EXPECT_EQ(0, unlimited_usage());
- GetGlobalUsage(kStorageTypePersistent);
+ GetGlobalUsage(kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, usage());
EXPECT_EQ(0, unlimited_usage());
@@ -441,23 +455,23 @@ TEST_F(QuotaManagerTest, GetUsage_EmptyClient) {
TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_MultiOrigins) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypeTemporary, 10 },
- { "http://foo.com:8080/", kStorageTypeTemporary, 20 },
- { "http://bar.com/", kStorageTypeTemporary, 5 },
- { "https://bar.com/", kStorageTypeTemporary, 7 },
- { "http://baz.com/", kStorageTypeTemporary, 30 },
- { "http://foo.com/", kStorageTypePersistent, 40 },
+ { "http://foo.com/", kTemp, 10 },
+ { "http://foo.com:8080/", kTemp, 20 },
+ { "http://bar.com/", kTemp, 5 },
+ { "https://bar.com/", kTemp, 7 },
+ { "http://baz.com/", kTemp, 30 },
+ { "http://foo.com/", kPerm, 40 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
// This time explicitly sets a temporary global quota.
SetTemporaryGlobalQuota(100);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kStorageTypeTemporary, type());
+ EXPECT_EQ(kTemp, type());
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(100, quota());
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 20, usage());
@@ -468,7 +482,7 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_MultiOrigins) {
// since global usage is under the global quota.
EXPECT_EQ(kPerHostQuota, quota());
- GetUsageAndQuota(GURL("http://bar.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://bar.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(5 + 7, usage());
@@ -477,49 +491,49 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_MultiOrigins) {
TEST_F(QuotaManagerTest, GetUsage_MultipleClients) {
static const MockOriginData kData1[] = {
- { "http://foo.com/", kStorageTypeTemporary, 10 },
- { "http://bar.com/", kStorageTypeTemporary, 20 },
- { "http://bar.com/", kStorageTypePersistent, 50 },
- { "http://unlimited/", kStorageTypePersistent, 1 },
+ { "http://foo.com/", kTemp, 10 },
+ { "http://bar.com/", kTemp, 20 },
+ { "http://bar.com/", kPerm, 50 },
+ { "http://unlimited/", kPerm, 1 },
};
static const MockOriginData kData2[] = {
- { "https://foo.com/", kStorageTypeTemporary, 30 },
- { "http://example.com/", kStorageTypePersistent, 40 },
- { "http://unlimited/", kStorageTypeTemporary, 1 },
+ { "https://foo.com/", kTemp, 30 },
+ { "http://example.com/", kPerm, 40 },
+ { "http://unlimited/", kTemp, 1 },
};
mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1)));
RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2)));
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 30, usage());
- GetUsageAndQuota(GURL("http://bar.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://bar.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(50, usage());
- GetUsageAndQuota(GURL("http://unlimited/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://unlimited/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(1, usage());
EXPECT_EQ(kint64max, quota());
- GetUsageAndQuota(GURL("http://unlimited/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://unlimited/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(1, usage());
EXPECT_EQ(kint64max, quota());
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 20 + 30 + 1, usage());
EXPECT_EQ(1, unlimited_usage());
- GetGlobalUsage(kStorageTypePersistent);
+ GetGlobalUsage(kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(40 + 50 + 1, usage());
@@ -562,15 +576,15 @@ void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) {
}
TEST_F(QuotaManagerTest, GetTemporaryUsage_WithModify) {
- GetUsage_WithModifyTestBody(kStorageTypeTemporary);
+ GetUsage_WithModifyTestBody(kTemp);
}
TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypeTemporary, 10 },
- { "http://foo.com:8080/", kStorageTypeTemporary, 20 },
- { "http://bar.com/", kStorageTypeTemporary, 13 },
- { "http://foo.com/", kStorageTypePersistent, 40 },
+ { "http://foo.com/", kTemp, 10 },
+ { "http://foo.com:8080/", kTemp, 20 },
+ { "http://bar.com/", kTemp, 13 },
+ { "http://foo.com/", kPerm, 40 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
SetTemporaryGlobalQuota(100);
@@ -578,9 +592,9 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) {
const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion;
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 20, usage());
@@ -588,10 +602,10 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) {
set_additional_callback_count(0);
RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
- kStorageTypeTemporary);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ kTemp);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"),
- kStorageTypeTemporary);
+ kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 20, usage());
@@ -601,21 +615,21 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) {
TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypeTemporary, 10 },
- { "http://foo.com:8080/", kStorageTypeTemporary, 20 },
- { "http://bar.com/", kStorageTypeTemporary, 13 },
- { "http://foo.com/", kStorageTypePersistent, 40 },
+ { "http://foo.com/", kTemp, 10 },
+ { "http://foo.com:8080/", kTemp, 20 },
+ { "http://bar.com/", kTemp, 13 },
+ { "http://foo.com/", kPerm, 40 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
SetTemporaryGlobalQuota(100);
MessageLoop::current()->RunAllPending();
set_additional_callback_count(0);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
- kStorageTypeTemporary);
+ kTemp);
RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"),
- kStorageTypeTemporary);
+ kTemp);
// Nuke before waiting for callbacks.
set_quota_manager(NULL);
@@ -625,9 +639,9 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) {
TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) {
static const MockOriginData kData[] = {
- { "http://usage1/", kStorageTypeTemporary, 1 },
- { "http://usage10/", kStorageTypeTemporary, 10 },
- { "http://usage200/", kStorageTypeTemporary, 200 },
+ { "http://usage1/", kTemp, 1 },
+ { "http://usage10/", kTemp, 10 },
+ { "http://usage200/", kTemp, 200 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
SetTemporaryGlobalQuota(100);
@@ -635,19 +649,19 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) {
const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion;
- GetUsageAndQuota(GURL("http://usage1/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://usage1/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(1, usage());
EXPECT_EQ(1, quota()); // should be clamped to our current usage
- GetUsageAndQuota(GURL("http://usage10/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://usage10/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10, usage());
EXPECT_EQ(10, quota());
- GetUsageAndQuota(GURL("http://usage200/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://usage200/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(200, usage());
@@ -656,9 +670,9 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) {
TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
static const MockOriginData kData[] = {
- { "http://usage10/", kStorageTypeTemporary, 10 },
- { "http://usage50/", kStorageTypeTemporary, 50 },
- { "http://unlimited/", kStorageTypeTemporary, 4000 },
+ { "http://usage10/", kTemp, 10 },
+ { "http://usage50/", kTemp, 50 },
+ { "http://unlimited/", kTemp, 4000 },
};
mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
@@ -671,19 +685,19 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
const int kPerHostQuotaFor1000 =
1000 / QuotaManager::kPerHostTemporaryPortion;
- GetUsageAndQuota(GURL("http://usage10/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://usage10/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10, usage());
EXPECT_EQ(kPerHostQuotaFor1000, quota());
- GetUsageAndQuota(GURL("http://usage50/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://usage50/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(50, usage());
EXPECT_EQ(kPerHostQuotaFor1000, quota());
- GetUsageAndQuota(GURL("http://unlimited/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://unlimited/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(4000, usage());
@@ -696,19 +710,19 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
const int kPerHostQuotaFor100 =
100 / QuotaManager::kPerHostTemporaryPortion;
- GetUsageAndQuota(GURL("http://usage10/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://usage10/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10, usage());
EXPECT_EQ(kPerHostQuotaFor100, quota());
- GetUsageAndQuota(GURL("http://usage50/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://usage50/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(50, usage());
EXPECT_EQ(kPerHostQuotaFor100, quota());
- GetUsageAndQuota(GURL("http://unlimited/"), kStorageTypeTemporary);
+ GetUsageAndQuota(GURL("http://unlimited/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(4000, usage());
@@ -743,7 +757,7 @@ TEST_F(QuotaManagerTest, GetAndSetPerststentHostQuota) {
GetPersistentHostQuota("foo.com");
MessageLoop::current()->RunAllPending();
EXPECT_EQ("foo.com", host());
- EXPECT_EQ(kStorageTypePersistent, type());
+ EXPECT_EQ(kPerm, type());
EXPECT_EQ(0, quota());
SetPersistentHostQuota("foo.com", 100);
@@ -762,14 +776,14 @@ TEST_F(QuotaManagerTest, GetAndSetPerststentHostQuota) {
TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) {
RegisterClient(CreateClient(NULL, 0));
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(0, usage());
EXPECT_EQ(0, quota());
SetPersistentHostQuota("foo.com", 100);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(0, usage());
@@ -778,19 +792,19 @@ TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) {
TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypePersistent, 10 },
- { "http://foo.com:8080/", kStorageTypePersistent, 20 },
- { "https://foo.com/", kStorageTypePersistent, 13 },
- { "https://foo.com:8081/", kStorageTypePersistent, 19 },
- { "http://bar.com/", kStorageTypePersistent, 5 },
- { "https://bar.com/", kStorageTypePersistent, 7 },
- { "http://baz.com/", kStorageTypePersistent, 30 },
- { "http://foo.com/", kStorageTypeTemporary, 40 },
+ { "http://foo.com/", kPerm, 10 },
+ { "http://foo.com:8080/", kPerm, 20 },
+ { "https://foo.com/", kPerm, 13 },
+ { "https://foo.com:8081/", kPerm, 19 },
+ { "http://bar.com/", kPerm, 5 },
+ { "https://bar.com/", kPerm, 7 },
+ { "http://baz.com/", kPerm, 30 },
+ { "http://foo.com/", kTemp, 40 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
SetPersistentHostQuota("foo.com", 100);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 20 + 13 + 19, usage());
@@ -798,22 +812,22 @@ TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) {
}
TEST_F(QuotaManagerTest, GetPersistentUsage_WithModify) {
- GetUsage_WithModifyTestBody(kStorageTypePersistent);
+ GetUsage_WithModifyTestBody(kPerm);
}
TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_WithAdditionalTasks) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypePersistent, 10 },
- { "http://foo.com:8080/", kStorageTypePersistent, 20 },
- { "http://bar.com/", kStorageTypePersistent, 13 },
- { "http://foo.com/", kStorageTypeTemporary, 40 },
+ { "http://foo.com/", kPerm, 10 },
+ { "http://foo.com:8080/", kPerm, 20 },
+ { "http://bar.com/", kPerm, 13 },
+ { "http://foo.com/", kTemp, 40 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
SetPersistentHostQuota("foo.com", 100);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 20, usage());
@@ -821,10 +835,10 @@ TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_WithAdditionalTasks) {
set_additional_callback_count(0);
RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
- kStorageTypePersistent);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ kPerm);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"),
- kStorageTypePersistent);
+ kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
EXPECT_EQ(10 + 20, usage());
@@ -833,20 +847,20 @@ TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_WithAdditionalTasks) {
TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypePersistent, 10 },
- { "http://foo.com:8080/", kStorageTypePersistent, 20 },
- { "http://bar.com/", kStorageTypePersistent, 13 },
- { "http://foo.com/", kStorageTypeTemporary, 40 },
+ { "http://foo.com/", kPerm, 10 },
+ { "http://foo.com:8080/", kPerm, 20 },
+ { "http://bar.com/", kPerm, 13 },
+ { "http://foo.com/", kTemp, 40 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
SetPersistentHostQuota("foo.com", 100);
set_additional_callback_count(0);
- GetUsageAndQuota(GURL("http://foo.com/"), kStorageTypePersistent);
+ GetUsageAndQuota(GURL("http://foo.com/"), kPerm);
RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
- kStorageTypePersistent);
+ kPerm);
RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"),
- kStorageTypePersistent);
+ kPerm);
// Nuke before waiting for callbacks.
set_quota_manager(NULL);
@@ -856,123 +870,123 @@ TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) {
TEST_F(QuotaManagerTest, GetUsage_Simple) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypePersistent, 1 },
- { "http://foo.com:1/", kStorageTypePersistent, 20 },
- { "http://bar.com/", kStorageTypeTemporary, 300 },
- { "https://buz.com/", kStorageTypeTemporary, 4000 },
- { "http://buz.com/", kStorageTypeTemporary, 50000 },
- { "http://bar.com:1/", kStorageTypePersistent, 600000 },
- { "http://foo.com/", kStorageTypeTemporary, 7000000 },
+ { "http://foo.com/", kPerm, 1 },
+ { "http://foo.com:1/", kPerm, 20 },
+ { "http://bar.com/", kTemp, 300 },
+ { "https://buz.com/", kTemp, 4000 },
+ { "http://buz.com/", kTemp, 50000 },
+ { "http://bar.com:1/", kPerm, 600000 },
+ { "http://foo.com/", kTemp, 7000000 },
};
RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData)));
- GetGlobalUsage(kStorageTypePersistent);
+ GetGlobalUsage(kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 1 + 20 + 600000);
EXPECT_EQ(0, unlimited_usage());
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000);
EXPECT_EQ(0, unlimited_usage());
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 1 + 20);
- GetHostUsage("buz.com", kStorageTypeTemporary);
+ GetHostUsage("buz.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 4000 + 50000);
}
TEST_F(QuotaManagerTest, GetUsage_WithModification) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypePersistent, 1 },
- { "http://foo.com:1/", kStorageTypePersistent, 20 },
- { "http://bar.com/", kStorageTypeTemporary, 300 },
- { "https://buz.com/", kStorageTypeTemporary, 4000 },
- { "http://buz.com/", kStorageTypeTemporary, 50000 },
- { "http://bar.com:1/", kStorageTypePersistent, 600000 },
- { "http://foo.com/", kStorageTypeTemporary, 7000000 },
+ { "http://foo.com/", kPerm, 1 },
+ { "http://foo.com:1/", kPerm, 20 },
+ { "http://bar.com/", kTemp, 300 },
+ { "https://buz.com/", kTemp, 4000 },
+ { "http://buz.com/", kTemp, 50000 },
+ { "http://bar.com:1/", kPerm, 600000 },
+ { "http://foo.com/", kTemp, 7000000 },
};
MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
RegisterClient(client);
- GetGlobalUsage(kStorageTypePersistent);
+ GetGlobalUsage(kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 1 + 20 + 600000);
EXPECT_EQ(0, unlimited_usage());
client->ModifyOriginAndNotify(
- GURL("http://foo.com/"), kStorageTypePersistent, 80000000);
+ GURL("http://foo.com/"), kPerm, 80000000);
- GetGlobalUsage(kStorageTypePersistent);
+ GetGlobalUsage(kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 1 + 20 + 600000 + 80000000);
EXPECT_EQ(0, unlimited_usage());
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000);
EXPECT_EQ(0, unlimited_usage());
client->ModifyOriginAndNotify(
- GURL("http://foo.com/"), kStorageTypeTemporary, 1);
+ GURL("http://foo.com/"), kTemp, 1);
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000 + 1);
EXPECT_EQ(0, unlimited_usage());
- GetHostUsage("buz.com", kStorageTypeTemporary);
+ GetHostUsage("buz.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 4000 + 50000);
client->ModifyOriginAndNotify(
- GURL("http://buz.com/"), kStorageTypeTemporary, 900000000);
+ GURL("http://buz.com/"), kTemp, 900000000);
- GetHostUsage("buz.com", kStorageTypeTemporary);
+ GetHostUsage("buz.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(usage(), 4000 + 50000 + 900000000);
}
TEST_F(QuotaManagerTest, GetUsage_WithDeleteOrigin) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypeTemporary, 1 },
- { "http://foo.com:1/", kStorageTypeTemporary, 20 },
- { "http://foo.com/", kStorageTypePersistent, 300 },
- { "http://bar.com/", kStorageTypeTemporary, 4000 },
+ { "http://foo.com/", kTemp, 1 },
+ { "http://foo.com:1/", kTemp, 20 },
+ { "http://foo.com/", kPerm, 300 },
+ { "http://bar.com/", kTemp, 4000 },
};
MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
RegisterClient(client);
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
int64 predelete_global_tmp = usage();
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
int64 predelete_host_tmp = usage();
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
int64 predelete_host_pers = usage();
DeleteClientOriginData(client, GURL("http://foo.com/"),
- kStorageTypeTemporary);
+ kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaStatusOk, status());
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_global_tmp - 1, usage());
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_host_tmp - 1, usage());
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_host_pers, usage());
}
@@ -986,32 +1000,32 @@ TEST_F(QuotaManagerTest, GetAvailableSpaceTest) {
TEST_F(QuotaManagerTest, EvictOriginData) {
static const MockOriginData kData1[] = {
- { "http://foo.com/", kStorageTypeTemporary, 1 },
- { "http://foo.com:1/", kStorageTypeTemporary, 20 },
- { "http://foo.com/", kStorageTypePersistent, 300 },
- { "http://bar.com/", kStorageTypeTemporary, 4000 },
+ { "http://foo.com/", kTemp, 1 },
+ { "http://foo.com:1/", kTemp, 20 },
+ { "http://foo.com/", kPerm, 300 },
+ { "http://bar.com/", kTemp, 4000 },
};
static const MockOriginData kData2[] = {
- { "http://foo.com/", kStorageTypeTemporary, 50000 },
- { "http://foo.com:1/", kStorageTypeTemporary, 6000 },
- { "http://foo.com/", kStorageTypePersistent, 700 },
- { "https://foo.com/", kStorageTypeTemporary, 80 },
- { "http://bar.com/", kStorageTypeTemporary, 9 },
+ { "http://foo.com/", kTemp, 50000 },
+ { "http://foo.com:1/", kTemp, 6000 },
+ { "http://foo.com/", kPerm, 700 },
+ { "https://foo.com/", kTemp, 80 },
+ { "http://bar.com/", kTemp, 9 },
};
MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1));
MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2));
RegisterClient(client1);
RegisterClient(client2);
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
int64 predelete_global_tmp = usage();
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
int64 predelete_host_tmp = usage();
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
int64 predelete_host_pers = usage();
@@ -1023,7 +1037,7 @@ TEST_F(QuotaManagerTest, EvictOriginData) {
GURL(kData2[i].origin), kData2[i].type);
MessageLoop::current()->RunAllPending();
- EvictOriginData(GURL("http://foo.com/"), kStorageTypeTemporary);
+ EvictOriginData(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
DumpLastAccessTimeTable();
@@ -1033,57 +1047,56 @@ TEST_F(QuotaManagerTest, EvictOriginData) {
for (iterator itr(last_access_time_table().begin()),
end(last_access_time_table().end());
itr != end; ++itr) {
- if (itr->type == kStorageTypeTemporary)
+ if (itr->type == kTemp)
EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec());
}
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage());
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage());
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_host_pers, usage());
}
TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypeTemporary, 1 },
- { "http://foo.com:1/", kStorageTypeTemporary, 20 },
- { "http://foo.com/", kStorageTypePersistent, 300 },
- { "http://bar.com/", kStorageTypeTemporary, 4000 },
+ { "http://foo.com/", kTemp, 1 },
+ { "http://foo.com:1/", kTemp, 20 },
+ { "http://foo.com/", kPerm, 300 },
+ { "http://bar.com/", kTemp, 4000 },
};
static const int kNumberOfTemporaryOrigins = 3;
MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
RegisterClient(client);
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
int64 predelete_global_tmp = usage();
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
int64 predelete_host_tmp = usage();
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
int64 predelete_host_pers = usage();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i)
- quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart,
- GURL(kData[i].origin), kData[i].type);
+ NotifyStorageAccessed(client, GURL(kData[i].origin), kData[i].type);
MessageLoop::current()->RunAllPending();
- client->AddOriginToErrorSet(GURL("http://foo.com/"), kStorageTypeTemporary);
+ client->AddOriginToErrorSet(GURL("http://foo.com/"), kTemp);
for (int i = 0;
i < QuotaManager::kThresholdOfErrorsToBeBlacklisted + 1;
++i) {
- EvictOriginData(GURL("http://foo.com/"), kStorageTypeTemporary);
+ EvictOriginData(GURL("http://foo.com/"), kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kQuotaErrorInvalidModification, status());
}
@@ -1096,7 +1109,7 @@ TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) {
for (iterator itr(last_access_time_table().begin()),
end(last_access_time_table().end());
itr != end; ++itr) {
- if (itr->type == kStorageTypeTemporary &&
+ if (itr->type == kTemp &&
GURL("http://foo.com/") == itr->origin) {
found_origin_in_database = true;
break;
@@ -1106,41 +1119,41 @@ TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) {
EXPECT_TRUE(found_origin_in_database);
for (size_t i = 0; i < kNumberOfTemporaryOrigins - 1; ++i) {
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_FALSE(lru_origin().is_empty());
// The origin "http://foo.com/" should not be in the LRU list.
EXPECT_NE(std::string("http://foo.com/"), lru_origin().spec());
- DeleteOriginFromDatabase(lru_origin(), kStorageTypeTemporary);
+ DeleteOriginFromDatabase(lru_origin(), kTemp);
MessageLoop::current()->RunAllPending();
}
// Now the LRU list must be empty.
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(lru_origin().is_empty());
// Deleting origins from the database should not affect the results of the
// following checks.
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_global_tmp, usage());
- GetHostUsage("foo.com", kStorageTypeTemporary);
+ GetHostUsage("foo.com", kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_host_tmp, usage());
- GetHostUsage("foo.com", kStorageTypePersistent);
+ GetHostUsage("foo.com", kPerm);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(predelete_host_pers, usage());
}
TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) {
static const MockOriginData kData[] = {
- { "http://foo.com/", kStorageTypeTemporary, 1 },
- { "http://foo.com:1/", kStorageTypeTemporary, 20 },
- { "http://foo.com/", kStorageTypePersistent, 300 },
- { "http://unlimited/", kStorageTypeTemporary, 4000 },
+ { "http://foo.com/", kTemp, 1 },
+ { "http://foo.com:1/", kTemp, 20 },
+ { "http://foo.com/", kPerm, 300 },
+ { "http://unlimited/", kTemp, 4000 },
};
mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
@@ -1161,10 +1174,10 @@ TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) {
TEST_F(QuotaManagerTest, GetCachedOrigins) {
static const MockOriginData kData[] = {
- { "http://a.com/", kStorageTypeTemporary, 1 },
- { "http://a.com:1/", kStorageTypeTemporary, 20 },
- { "http://b.com/", kStorageTypePersistent, 300 },
- { "http://c.com/", kStorageTypeTemporary, 4000 },
+ { "http://a.com/", kTemp, 1 },
+ { "http://a.com:1/", kTemp, 20 },
+ { "http://b.com/", kPerm, 300 },
+ { "http://c.com/", kTemp, 4000 },
};
MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
RegisterClient(client);
@@ -1172,117 +1185,106 @@ TEST_F(QuotaManagerTest, GetCachedOrigins) {
// TODO(kinuko): Be careful when we add cache pruner.
std::set<GURL> origins;
- GetCachedOrigins(kStorageTypeTemporary, &origins);
+ GetCachedOrigins(kTemp, &origins);
EXPECT_TRUE(origins.empty());
// Make the cache hot.
- GetHostUsage("a.com", kStorageTypeTemporary);
+ GetHostUsage("a.com", kTemp);
MessageLoop::current()->RunAllPending();
- GetCachedOrigins(kStorageTypeTemporary, &origins);
+ GetCachedOrigins(kTemp, &origins);
EXPECT_EQ(2U, origins.size());
- GetHostUsage("b.com", kStorageTypeTemporary);
+ GetHostUsage("b.com", kTemp);
MessageLoop::current()->RunAllPending();
- GetCachedOrigins(kStorageTypeTemporary, &origins);
+ GetCachedOrigins(kTemp, &origins);
EXPECT_EQ(2U, origins.size());
- GetCachedOrigins(kStorageTypePersistent, &origins);
+ GetCachedOrigins(kPerm, &origins);
EXPECT_TRUE(origins.empty());
- GetGlobalUsage(kStorageTypeTemporary);
+ GetGlobalUsage(kTemp);
MessageLoop::current()->RunAllPending();
- GetCachedOrigins(kStorageTypeTemporary, &origins);
+ GetCachedOrigins(kTemp, &origins);
EXPECT_EQ(3U, origins.size());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) {
- if (kData[i].type == kStorageTypeTemporary)
+ if (kData[i].type == kTemp)
EXPECT_TRUE(origins.find(GURL(kData[i].origin)) != origins.end());
}
}
-#if defined(OS_WIN)
-// http://crbug.com/83805. Time is too granular for the LRU tests on
-// Windows, and a new version of SQLite is returning values in a
-// different (implementation-defined and appropriate) order.
-#define MAYBE_NotifyAndLRUOrigin DISABLED_NotifyAndLRUOrigin
-#define MAYBE_GetLRUOriginWithOriginInUse DISABLED_GetLRUOriginWithOriginInUse
-#else
-#define MAYBE_NotifyAndLRUOrigin NotifyAndLRUOrigin
-#define MAYBE_GetLRUOriginWithOriginInUse GetLRUOriginWithOriginInUse
-#endif
-
-TEST_F(QuotaManagerTest, MAYBE_NotifyAndLRUOrigin) {
+TEST_F(QuotaManagerTest, NotifyAndLRUOrigin) {
static const MockOriginData kData[] = {
- { "http://a.com/", kStorageTypeTemporary, 0 },
- { "http://a.com:1/", kStorageTypeTemporary, 0 },
- { "https://a.com/", kStorageTypeTemporary, 0 },
- { "http://b.com/", kStorageTypePersistent, 0 }, // persistent
- { "http://c.com/", kStorageTypeTemporary, 0 },
+ { "http://a.com/", kTemp, 0 },
+ { "http://a.com:1/", kTemp, 0 },
+ { "https://a.com/", kTemp, 0 },
+ { "http://b.com/", kPerm, 0 }, // persistent
+ { "http://c.com/", kTemp, 0 },
};
MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
RegisterClient(client);
GURL origin;
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(lru_origin().is_empty());
- NotifyStorageAccessed(client, GURL("http://a.com/"), kStorageTypeTemporary);
- GetLRUOrigin(kStorageTypeTemporary);
+ NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ("http://a.com/", lru_origin().spec());
- NotifyStorageAccessed(client, GURL("http://b.com/"), kStorageTypePersistent);
- NotifyStorageAccessed(client, GURL("https://a.com/"), kStorageTypeTemporary);
- NotifyStorageAccessed(client, GURL("http://c.com/"), kStorageTypeTemporary);
- GetLRUOrigin(kStorageTypeTemporary);
+ NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm);
+ NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp);
+ NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ("http://a.com/", lru_origin().spec());
- DeleteOriginFromDatabase(lru_origin(), kStorageTypeTemporary);
- GetLRUOrigin(kStorageTypeTemporary);
+ DeleteOriginFromDatabase(lru_origin(), kTemp);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ("https://a.com/", lru_origin().spec());
- DeleteOriginFromDatabase(lru_origin(), kStorageTypeTemporary);
- GetLRUOrigin(kStorageTypeTemporary);
+ DeleteOriginFromDatabase(lru_origin(), kTemp);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ("http://c.com/", lru_origin().spec());
}
-TEST_F(QuotaManagerTest, MAYBE_GetLRUOriginWithOriginInUse) {
+TEST_F(QuotaManagerTest, GetLRUOriginWithOriginInUse) {
static const MockOriginData kData[] = {
- { "http://a.com/", kStorageTypeTemporary, 0 },
- { "http://a.com:1/", kStorageTypeTemporary, 0 },
- { "https://a.com/", kStorageTypeTemporary, 0 },
- { "http://b.com/", kStorageTypePersistent, 0 }, // persistent
- { "http://c.com/", kStorageTypeTemporary, 0 },
+ { "http://a.com/", kTemp, 0 },
+ { "http://a.com:1/", kTemp, 0 },
+ { "https://a.com/", kTemp, 0 },
+ { "http://b.com/", kPerm, 0 }, // persistent
+ { "http://c.com/", kTemp, 0 },
};
MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
RegisterClient(client);
GURL origin;
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(lru_origin().is_empty());
- NotifyStorageAccessed(client, GURL("http://a.com/"), kStorageTypeTemporary);
- NotifyStorageAccessed(client, GURL("http://b.com/"), kStorageTypePersistent);
- NotifyStorageAccessed(client, GURL("https://a.com/"), kStorageTypeTemporary);
- NotifyStorageAccessed(client, GURL("http://c.com/"), kStorageTypeTemporary);
+ NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp);
+ NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm);
+ NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp);
+ NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp);
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ("http://a.com/", lru_origin().spec());
// Notify origin http://a.com is in use.
NotifyOriginInUse(GURL("http://a.com/"));
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ("https://a.com/", lru_origin().spec());
// Notify origin https://a.com is in use while GetLRUOrigin is running.
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
NotifyOriginInUse(GURL("https://a.com/"));
MessageLoop::current()->RunAllPending();
// Post-filtering must have excluded the returned origin, so we will
@@ -1290,8 +1292,8 @@ TEST_F(QuotaManagerTest, MAYBE_GetLRUOriginWithOriginInUse) {
EXPECT_TRUE(lru_origin().is_empty());
// Notify access for http://c.com while GetLRUOrigin is running.
- GetLRUOrigin(kStorageTypeTemporary);
- NotifyStorageAccessed(client, GURL("http://c.com/"), kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
+ NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp);
MessageLoop::current()->RunAllPending();
// Post-filtering must have excluded the returned origin, so we will
// see empty result here.
@@ -1299,7 +1301,7 @@ TEST_F(QuotaManagerTest, MAYBE_GetLRUOriginWithOriginInUse) {
NotifyOriginNoLongerInUse(GURL("http://a.com/"));
NotifyOriginNoLongerInUse(GURL("https://a.com/"));
- GetLRUOrigin(kStorageTypeTemporary);
+ GetLRUOrigin(kTemp);
MessageLoop::current()->RunAllPending();
EXPECT_EQ("http://a.com/", lru_origin().spec());
}
@@ -1314,9 +1316,9 @@ TEST_F(QuotaManagerTest, DumpQuotaTable) {
MessageLoop::current()->RunAllPending();
const QuotaTableEntry kEntries[] = {
- {"example1.com", kStorageTypePersistent, 1},
- {"example2.com", kStorageTypePersistent, 20},
- {"example3.com", kStorageTypePersistent, 300},
+ {"example1.com", kPerm, 1},
+ {"example2.com", kPerm, 20},
+ {"example3.com", kPerm, 300},
};
std::set<QuotaTableEntry> entries
(kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries));
@@ -1338,15 +1340,15 @@ TEST_F(QuotaManagerTest, DumpLastAccessTimeTable) {
quota_manager()->NotifyStorageAccessed(
QuotaClient::kMockStart,
GURL("http://example.com/"),
- kStorageTypeTemporary);
+ kTemp);
quota_manager()->NotifyStorageAccessed(
QuotaClient::kMockStart,
GURL("http://example.com/"),
- kStorageTypePersistent);
+ kPerm);
quota_manager()->NotifyStorageAccessed(
QuotaClient::kMockStart,
GURL("http://example.com/"),
- kStorageTypePersistent);
+ kPerm);
MessageLoop::current()->RunAllPending();
DumpLastAccessTimeTable();
@@ -1355,10 +1357,8 @@ TEST_F(QuotaManagerTest, DumpLastAccessTimeTable) {
typedef std::pair<GURL, StorageType> TypedOrigin;
typedef std::pair<TypedOrigin, int> Entry;
const Entry kEntries[] = {
- make_pair(make_pair(GURL("http://example.com/"),
- kStorageTypeTemporary), 1),
- make_pair(make_pair(GURL("http://example.com/"),
- kStorageTypePersistent), 2),
+ make_pair(make_pair(GURL("http://example.com/"), kTemp), 1),
+ make_pair(make_pair(GURL("http://example.com/"), kPerm), 2),
};
std::set<Entry> entries
(kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries));