summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_storage_impl_unittest.cc
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 20:01:37 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 20:01:37 +0000
commitbae3069e31b61b1555f65272ec8973b2f4c56df5 (patch)
tree6edca4e598e62e1bbc87fc0a96ba99293d103686 /webkit/appcache/appcache_storage_impl_unittest.cc
parent5fd7738372b76c4a1951e6b842e6387cd09d2521 (diff)
downloadchromium_src-bae3069e31b61b1555f65272ec8973b2f4c56df5.zip
chromium_src-bae3069e31b61b1555f65272ec8973b2f4c56df5.tar.gz
chromium_src-bae3069e31b61b1555f65272ec8973b2f4c56df5.tar.bz2
AppCache: Provide a way to override the default quota for an origin. The intent is to use this to support the 'unlimited_storage' privilege of Chrome Applications.
BUG=49993 TEST=AppCacheStorageImplTest.FailStoreGroup Review URL: http://codereview.chromium.org/3083014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_storage_impl_unittest.cc')
-rw-r--r--webkit/appcache/appcache_storage_impl_unittest.cc56
1 files changed, 54 insertions, 2 deletions
diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc
index 8367cf8..5fccade 100644
--- a/webkit/appcache/appcache_storage_impl_unittest.cc
+++ b/webkit/appcache/appcache_storage_impl_unittest.cc
@@ -73,8 +73,9 @@ class AppCacheStorageImplTest : public testing::Test {
public:
explicit MockStorageDelegate(AppCacheStorageImplTest* test)
: loaded_cache_id_(0), stored_group_success_(false),
- obsoleted_success_(false), found_cache_id_(kNoCacheId),
- found_blocked_by_policy_(false), test_(test) {
+ would_exceed_quota_(false), obsoleted_success_(false),
+ found_cache_id_(kNoCacheId), found_blocked_by_policy_(false),
+ test_(test) {
}
void OnCacheLoaded(AppCache* cache, int64 cache_id) {
@@ -96,6 +97,7 @@ class AppCacheStorageImplTest : public testing::Test {
bool would_exceed_quota) {
stored_group_ = group;
stored_group_success_ = success;
+ would_exceed_quota_ = would_exceed_quota;
test_->ScheduleNextTask();
}
@@ -125,6 +127,7 @@ class AppCacheStorageImplTest : public testing::Test {
scoped_refptr<AppCache> loaded_groups_newest_cache_;
scoped_refptr<AppCacheGroup> stored_group_;
bool stored_group_success_;
+ bool would_exceed_quota_;
scoped_refptr<AppCacheGroup> obsoleted_group_;
bool obsoleted_success_;
GURL found_url_;
@@ -532,6 +535,51 @@ class AppCacheStorageImplTest : public testing::Test {
TestFinished();
}
+ // FailStoreGroup --------------------------------------
+
+ void FailStoreGroup() {
+ // Store a group and its newest cache. Should complete asyncly.
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_FailStoreGroup));
+
+ // Set a low quota to force a failure.
+ const GURL kOrigin(kManifestUrl.GetOrigin());
+ EXPECT_EQ(-1L, storage()->GetOriginQuotaInMemory(kOrigin));
+ storage()->SetOriginQuotaInMemory(kManifestUrl.GetOrigin(), 0);
+ EXPECT_EQ(0L, storage()->GetOriginQuotaInMemory(kOrigin));
+
+ // Setup some preconditions. Create a group and newest cache that
+ // appear to be "unstored".
+ group_ = new AppCacheGroup(
+ service(), kManifestUrl, storage()->NewGroupId());
+ cache_ = new AppCache(service(), storage()->NewCacheId());
+ cache_->AddEntry(kManifestUrl,
+ AppCacheEntry(AppCacheEntry::MANIFEST, 1, 1024));
+ // Hold a ref to the cache simulate the UpdateJob holding that ref,
+ // and hold a ref to the group to simulate the CacheHost holding that ref.
+
+ // Conduct the store test.
+ storage()->StoreGroupAndNewestCache(group_, cache_, delegate());
+ EXPECT_FALSE(delegate()->stored_group_success_); // Expected to be async.
+ }
+
+ void Verify_FailStoreGroup() {
+ EXPECT_FALSE(delegate()->stored_group_success_);
+ EXPECT_TRUE(delegate()->would_exceed_quota_);
+
+ // Should not have been stored in the database.
+ AppCacheDatabase::GroupRecord group_record;
+ AppCacheDatabase::CacheRecord cache_record;
+ EXPECT_FALSE(database()->FindGroup(group_->group_id(), &group_record));
+ EXPECT_FALSE(database()->FindCache(cache_->cache_id(), &cache_record));
+
+ const GURL kOrigin(kManifestUrl.GetOrigin());
+ storage()->ResetOriginQuotaInMemory(kOrigin);
+ EXPECT_EQ(-1L, storage()->GetOriginQuotaInMemory(kOrigin));
+
+ TestFinished();
+ }
+
// MakeGroupObsolete -------------------------------
void MakeGroupObsolete() {
@@ -1006,6 +1054,10 @@ TEST_F(AppCacheStorageImplTest, StoreExistingGroupExistingCache) {
RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroupExistingCache);
}
+TEST_F(AppCacheStorageImplTest, FailStoreGroup) {
+ RunTestOnIOThread(&AppCacheStorageImplTest::FailStoreGroup);
+}
+
TEST_F(AppCacheStorageImplTest, MakeGroupObsolete) {
RunTestOnIOThread(&AppCacheStorageImplTest::MakeGroupObsolete);
}