summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_database_unittest.cc
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 21:39:23 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 21:39:23 +0000
commit31be98b016611afba449aace847074724f51e22d (patch)
tree88c7cf441d37d26a4f7eff0182669035aa8ae35c /webkit/appcache/appcache_database_unittest.cc
parent349e8d271a90f15a4746412c93706cc9f78e4520 (diff)
downloadchromium_src-31be98b016611afba449aace847074724f51e22d.zip
chromium_src-31be98b016611afba449aace847074724f51e22d.tar.gz
chromium_src-31be98b016611afba449aace847074724f51e22d.tar.bz2
Add a DeletableResponseIds table to the appcache database schema, groundwork for purging unused responses from the disk cache.
TEST=yes BUG=none Review URL: http://codereview.chromium.org/523157 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35829 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_database_unittest.cc')
-rw-r--r--webkit/appcache/appcache_database_unittest.cc79
1 files changed, 76 insertions, 3 deletions
diff --git a/webkit/appcache/appcache_database_unittest.cc b/webkit/appcache/appcache_database_unittest.cc
index 11452c8..2ee25da 100644
--- a/webkit/appcache/appcache_database_unittest.cc
+++ b/webkit/appcache/appcache_database_unittest.cc
@@ -37,12 +37,14 @@ TEST(AppCacheDatabaseTest, LazyOpen) {
EXPECT_FALSE(db.LazyOpen(false));
EXPECT_TRUE(db.LazyOpen(true));
- int64 group_id, cache_id, response_id;
- group_id = cache_id = response_id = 0;
- EXPECT_TRUE(db.FindLastStorageIds(&group_id, &cache_id, &response_id));
+ int64 group_id, cache_id, response_id, deleteable_response_rowid;
+ group_id = cache_id = response_id = deleteable_response_rowid = 0;
+ EXPECT_TRUE(db.FindLastStorageIds(&group_id, &cache_id, &response_id,
+ &deleteable_response_rowid));
EXPECT_EQ(0, group_id);
EXPECT_EQ(0, cache_id);
EXPECT_EQ(0, response_id);
+ EXPECT_EQ(0, deleteable_response_rowid);
std::set<GURL> origins;
EXPECT_TRUE(db.FindOriginsWithGroups(&origins));
@@ -444,4 +446,75 @@ TEST(AppCacheDatabaseTest, OnlineWhiteListRecords) {
EXPECT_TRUE(records.empty());
}
+TEST(AppCacheDatabaseTest, DeletableResponseIds) {
+ const FilePath kEmptyPath;
+ AppCacheDatabase db(kEmptyPath);
+ EXPECT_TRUE(db.LazyOpen(true));
+
+ scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate);
+ db.db_->set_error_delegate(error_delegate);
+
+ std::vector<int64> ids;
+
+ EXPECT_TRUE(db.GetDeletableResponseIds(&ids, kint64max, 100));
+ EXPECT_TRUE(ids.empty());
+ ids.push_back(0);
+ EXPECT_TRUE(db.DeleteDeletableResponseIds(ids));
+ EXPECT_TRUE(db.InsertDeletableResponseIds(ids));
+
+ ids.clear();
+ EXPECT_TRUE(db.GetDeletableResponseIds(&ids, kint64max, 100));
+ EXPECT_EQ(1U, ids.size());
+ EXPECT_EQ(0, ids[0]);
+
+ int64 unused, deleteable_response_rowid;
+ unused = deleteable_response_rowid = 0;
+ EXPECT_TRUE(db.FindLastStorageIds(&unused, &unused, &unused,
+ &deleteable_response_rowid));
+ EXPECT_EQ(1, deleteable_response_rowid);
+
+
+ // Expected to fail due to the duplicate id, 0 is already in the table.
+ ids.clear();
+ ids.push_back(0);
+ ids.push_back(1);
+ EXPECT_FALSE(db.InsertDeletableResponseIds(ids));
+
+ ids.clear();
+ for (int i = 1; i < 10; ++i)
+ ids.push_back(i);
+ EXPECT_TRUE(db.InsertDeletableResponseIds(ids));
+ EXPECT_TRUE(db.FindLastStorageIds(&unused, &unused, &unused,
+ &deleteable_response_rowid));
+ EXPECT_EQ(10, deleteable_response_rowid);
+
+ ids.clear();
+ EXPECT_TRUE(db.GetDeletableResponseIds(&ids, kint64max, 100));
+ EXPECT_EQ(10U, ids.size());
+ for (int i = 0; i < 10; ++i)
+ EXPECT_EQ(i, ids[i]);
+
+ // Ensure the limit is respected.
+ ids.clear();
+ EXPECT_TRUE(db.GetDeletableResponseIds(&ids, kint64max, 5));
+ EXPECT_EQ(5U, ids.size());
+ for (size_t i = 0; i < ids.size(); ++i)
+ EXPECT_EQ(i, ids[i]);
+
+ // Ensure the max_rowid is respected (the first rowid is 1).
+ ids.clear();
+ EXPECT_TRUE(db.GetDeletableResponseIds(&ids, 5, 100));
+ EXPECT_EQ(5U, ids.size());
+ for (size_t i = 0; i < ids.size(); ++i)
+ EXPECT_EQ(i, ids[i]);
+
+ // Ensure that we can delete from the table.
+ EXPECT_TRUE(db.DeleteDeletableResponseIds(ids));
+ ids.clear();
+ EXPECT_TRUE(db.GetDeletableResponseIds(&ids, kint64max, 100));
+ EXPECT_EQ(5U, ids.size());
+ for (size_t i = 0; i < ids.size(); ++i)
+ EXPECT_EQ(i + 5, ids[i]);
+}
+
} // namespace appcache