summaryrefslogtreecommitdiffstats
path: root/webkit/quota/quota_database_unittest.cc
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 17:18:02 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 17:18:02 +0000
commit0179f39b00af02a9abde26f5003f213e25a4444a (patch)
tree4f0164d15fd13a7b9badbf2d52463a505a44060a /webkit/quota/quota_database_unittest.cc
parent6658e7822f61494fbf91a8e9075ae81cf94d59be (diff)
downloadchromium_src-0179f39b00af02a9abde26f5003f213e25a4444a.zip
chromium_src-0179f39b00af02a9abde26f5003f213e25a4444a.tar.gz
chromium_src-0179f39b00af02a9abde26f5003f213e25a4444a.tar.bz2
QuotaManager shouldn't crash if is_incognito is true.
BUG=82698 TEST=existing test chrome\test\functional\databases.py Review URL: http://codereview.chromium.org/7031016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85645 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota/quota_database_unittest.cc')
-rw-r--r--webkit/quota/quota_database_unittest.cc244
1 files changed, 132 insertions, 112 deletions
diff --git a/webkit/quota/quota_database_unittest.cc b/webkit/quota/quota_database_unittest.cc
index 369ac3b0..5f6c1cc 100644
--- a/webkit/quota/quota_database_unittest.cc
+++ b/webkit/quota/quota_database_unittest.cc
@@ -27,141 +27,161 @@ class TestErrorDelegate : public sql::ErrorDelegate {
namespace quota {
-TEST(QuotaDatabaseTest, LazyOpen) {
- ScopedTempDir data_dir;
- ASSERT_TRUE(data_dir.CreateUniqueTempDir());
+class QuotaDatabaseTest : public testing::Test {
+ protected:
+ void LazyOpen(const FilePath& kDbFile) {
+ QuotaDatabase db(kDbFile);
+ EXPECT_FALSE(db.LazyOpen(false));
+ ASSERT_TRUE(db.LazyOpen(true));
+ EXPECT_TRUE(db.db_.get());
+ EXPECT_TRUE(kDbFile.empty() || file_util::PathExists(kDbFile));
+ }
- const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db");
- QuotaDatabase db(kDbFile);
- EXPECT_FALSE(db.LazyOpen(false));
- ASSERT_TRUE(db.LazyOpen(true));
- EXPECT_TRUE(file_util::PathExists(kDbFile));
-}
+ void HostQuota(const FilePath& kDbFile) {
+ QuotaDatabase db(kDbFile);
+ ASSERT_TRUE(db.LazyOpen(true));
-TEST(QuotaDatabaseTest, HostQuota) {
- ScopedTempDir data_dir;
- ASSERT_TRUE(data_dir.CreateUniqueTempDir());
+ const char* kHost = "foo.com";
+ const int kQuota1 = 13579;
+ const int kQuota2 = kQuota1 + 1024;
- const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db");
- QuotaDatabase db(kDbFile);
- ASSERT_TRUE(db.LazyOpen(true));
+ int64 quota = -1;
+ EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
+ EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
- const char* kHost = "foo.com";
- const int kQuota1 = 13579;
- const int kQuota2 = kQuota1 + 1024;
+ // Insert quota for temporary.
+ EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota1));
+ EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
+ EXPECT_EQ(kQuota1, quota);
- int64 quota = -1;
- EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
- EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
+ // Update quota for temporary.
+ EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota2));
+ EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
+ EXPECT_EQ(kQuota2, quota);
- // Insert quota for temporary.
- EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota1));
- EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
- EXPECT_EQ(kQuota1, quota);
+ // Quota for persistent must not be updated.
+ EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
- // Update quota for temporary.
- EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota2));
- EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
- EXPECT_EQ(kQuota2, quota);
+ // Delete temporary storage quota.
+ EXPECT_TRUE(db.DeleteHostQuota(kHost, kStorageTypeTemporary));
+ EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
+ }
- // Quota for persistent must not be updated.
- EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
+ void GlobalQuota(const FilePath& kDbFile) {
+ QuotaDatabase db(kDbFile);
+ ASSERT_TRUE(db.LazyOpen(true));
- // Delete temporary storage quota.
- EXPECT_TRUE(db.DeleteHostQuota(kHost, kStorageTypeTemporary));
- EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
-}
+ const int kQuota1 = 9999;
+ const int kQuota2 = 86420;
-TEST(QuotaDatabaseTest, GlobalQuota) {
- ScopedTempDir data_dir;
- ASSERT_TRUE(data_dir.CreateUniqueTempDir());
+ int64 quota = -1;
+ EXPECT_FALSE(db.GetGlobalQuota(kStorageTypeTemporary, &quota));
+ EXPECT_FALSE(db.GetGlobalQuota(kStorageTypePersistent, &quota));
- const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db");
- QuotaDatabase db(kDbFile);
- ASSERT_TRUE(db.LazyOpen(true));
+ EXPECT_TRUE(db.SetGlobalQuota(kStorageTypeTemporary, kQuota1));
+ EXPECT_TRUE(db.GetGlobalQuota(kStorageTypeTemporary, &quota));
+ EXPECT_EQ(kQuota1, quota);
- const int kQuota1 = 9999;
- const int kQuota2 = 86420;
+ EXPECT_TRUE(db.SetGlobalQuota(kStorageTypeTemporary, kQuota1 + 1024));
+ EXPECT_TRUE(db.GetGlobalQuota(kStorageTypeTemporary, &quota));
+ EXPECT_EQ(kQuota1 + 1024, quota);
- int64 quota = -1;
- EXPECT_FALSE(db.GetGlobalQuota(kStorageTypeTemporary, &quota));
- EXPECT_FALSE(db.GetGlobalQuota(kStorageTypePersistent, &quota));
+ EXPECT_FALSE(db.GetGlobalQuota(kStorageTypePersistent, &quota));
- EXPECT_TRUE(db.SetGlobalQuota(kStorageTypeTemporary, kQuota1));
- EXPECT_TRUE(db.GetGlobalQuota(kStorageTypeTemporary, &quota));
- EXPECT_EQ(kQuota1, quota);
+ EXPECT_TRUE(db.SetGlobalQuota(kStorageTypePersistent, kQuota2));
+ EXPECT_TRUE(db.GetGlobalQuota(kStorageTypePersistent, &quota));
+ EXPECT_EQ(kQuota2, quota);
+ }
- EXPECT_TRUE(db.SetGlobalQuota(kStorageTypeTemporary, kQuota1 + 1024));
- EXPECT_TRUE(db.GetGlobalQuota(kStorageTypeTemporary, &quota));
- EXPECT_EQ(kQuota1 + 1024, quota);
+ void OriginLastAccessTimeLRU(const FilePath& kDbFile) {
+ QuotaDatabase db(kDbFile);
+ ASSERT_TRUE(db.LazyOpen(true));
+
+ std::set<GURL> exceptions;
+ GURL origin;
+ EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
+ EXPECT_TRUE(origin.is_empty());
+
+ const GURL kOrigin1("http://a/");
+ const GURL kOrigin2("http://b/");
+ const GURL kOrigin3("http://c/");
+ const GURL kOrigin4("http://p/");
+
+ // Adding three temporary storages, and
+ EXPECT_TRUE(db.SetOriginLastAccessTime(
+ kOrigin1, kStorageTypeTemporary, base::Time::FromInternalValue(10)));
+ EXPECT_TRUE(db.SetOriginLastAccessTime(
+ kOrigin2, kStorageTypeTemporary, base::Time::FromInternalValue(20)));
+ EXPECT_TRUE(db.SetOriginLastAccessTime(
+ kOrigin3, kStorageTypeTemporary, base::Time::FromInternalValue(30)));
+
+ // one persistent.
+ EXPECT_TRUE(db.SetOriginLastAccessTime(
+ kOrigin4, kStorageTypePersistent, base::Time::FromInternalValue(40)));
+
+ EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
+ EXPECT_EQ(kOrigin1.spec(), origin.spec());
+
+ exceptions.insert(kOrigin1);
+ EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
+ EXPECT_EQ(kOrigin2.spec(), origin.spec());
+
+ exceptions.insert(kOrigin2);
+ EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
+ EXPECT_EQ(kOrigin3.spec(), origin.spec());
+
+ exceptions.insert(kOrigin3);
+ EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
+ EXPECT_TRUE(origin.is_empty());
+
+ EXPECT_TRUE(db.SetOriginLastAccessTime(
+ kOrigin1, kStorageTypeTemporary, base::Time::Now()));
+
+ // Delete origin/type last access time information.
+ EXPECT_TRUE(db.DeleteOriginLastAccessTime(kOrigin3, kStorageTypeTemporary));
+
+ // Querying again to see if the deletion has worked.
+ exceptions.clear();
+ EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
+ EXPECT_EQ(kOrigin2.spec(), origin.spec());
+
+ exceptions.insert(kOrigin1);
+ exceptions.insert(kOrigin2);
+ EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
+ EXPECT_TRUE(origin.is_empty());
+ }
+};
- EXPECT_FALSE(db.GetGlobalQuota(kStorageTypePersistent, &quota));
+TEST_F(QuotaDatabaseTest, LazyOpen) {
+ ScopedTempDir data_dir;
+ ASSERT_TRUE(data_dir.CreateUniqueTempDir());
+ const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db");
+ LazyOpen(kDbFile);
+ LazyOpen(FilePath());
+}
- EXPECT_TRUE(db.SetGlobalQuota(kStorageTypePersistent, kQuota2));
- EXPECT_TRUE(db.GetGlobalQuota(kStorageTypePersistent, &quota));
- EXPECT_EQ(kQuota2, quota);
+TEST_F(QuotaDatabaseTest, HostQuota) {
+ ScopedTempDir data_dir;
+ ASSERT_TRUE(data_dir.CreateUniqueTempDir());
+ const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db");
+ HostQuota(kDbFile);
+ HostQuota(FilePath());
}
-TEST(QuotaDatabaseTest, OriginLastAccessTimeLRU) {
+TEST_F(QuotaDatabaseTest, GlobalQuota) {
ScopedTempDir data_dir;
ASSERT_TRUE(data_dir.CreateUniqueTempDir());
+ const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db");
+ GlobalQuota(kDbFile);
+ GlobalQuota(FilePath());
+}
+TEST_F(QuotaDatabaseTest, OriginLastAccessTimeLRU) {
+ ScopedTempDir data_dir;
+ ASSERT_TRUE(data_dir.CreateUniqueTempDir());
const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db");
- QuotaDatabase db(kDbFile);
- ASSERT_TRUE(db.LazyOpen(true));
-
- std::set<GURL> exceptions;
- GURL origin;
- EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
- EXPECT_TRUE(origin.is_empty());
-
- const GURL kOrigin1("http://a/");
- const GURL kOrigin2("http://b/");
- const GURL kOrigin3("http://c/");
- const GURL kOrigin4("http://p/");
-
- // Adding three temporary storages, and
- EXPECT_TRUE(db.SetOriginLastAccessTime(
- kOrigin1, kStorageTypeTemporary, base::Time::FromInternalValue(10)));
- EXPECT_TRUE(db.SetOriginLastAccessTime(
- kOrigin2, kStorageTypeTemporary, base::Time::FromInternalValue(20)));
- EXPECT_TRUE(db.SetOriginLastAccessTime(
- kOrigin3, kStorageTypeTemporary, base::Time::FromInternalValue(30)));
-
- // one persistent.
- EXPECT_TRUE(db.SetOriginLastAccessTime(
- kOrigin4, kStorageTypePersistent, base::Time::FromInternalValue(40)));
-
- EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
- EXPECT_EQ(kOrigin1.spec(), origin.spec());
-
- exceptions.insert(kOrigin1);
- EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
- EXPECT_EQ(kOrigin2.spec(), origin.spec());
-
- exceptions.insert(kOrigin2);
- EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
- EXPECT_EQ(kOrigin3.spec(), origin.spec());
-
- exceptions.insert(kOrigin3);
- EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
- EXPECT_TRUE(origin.is_empty());
-
- EXPECT_TRUE(db.SetOriginLastAccessTime(
- kOrigin1, kStorageTypeTemporary, base::Time::Now()));
-
- // Delete origin/type last access time information.
- EXPECT_TRUE(db.DeleteOriginLastAccessTime(kOrigin3, kStorageTypeTemporary));
-
- // Querying again to see if the deletion has worked.
- exceptions.clear();
- EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
- EXPECT_EQ(kOrigin2.spec(), origin.spec());
-
- exceptions.insert(kOrigin1);
- exceptions.insert(kOrigin2);
- EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions, &origin));
- EXPECT_TRUE(origin.is_empty());
+ OriginLastAccessTimeLRU(kDbFile);
+ OriginLastAccessTimeLRU(FilePath());
}
} // namespace quota