summaryrefslogtreecommitdiffstats
path: root/webkit/appcache
diff options
context:
space:
mode:
authorjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-18 22:22:37 +0000
committerjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-18 22:22:37 +0000
commit91fce0c025e0ff1516d1a8ea762bc4eab326b8de (patch)
tree3a8f22ff91e21328dcb5d9db7ad3b4f4cc7c609f /webkit/appcache
parent7f1654c7b6a85ec08b0080b68124bb39471b1a16 (diff)
downloadchromium_src-91fce0c025e0ff1516d1a8ea762bc4eab326b8de.zip
chromium_src-91fce0c025e0ff1516d1a8ea762bc4eab326b8de.tar.gz
chromium_src-91fce0c025e0ff1516d1a8ea762bc4eab326b8de.tar.bz2
Mock appcache storage bug fix for storing group and changes to its existing newest cache.
TEST=test added to catch bug BUG=none Review URL: http://codereview.chromium.org/399078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r--webkit/appcache/mock_appcache_storage.cc16
-rw-r--r--webkit/appcache/mock_appcache_storage.h1
-rw-r--r--webkit/appcache/mock_appcache_storage_unittest.cc42
3 files changed, 52 insertions, 7 deletions
diff --git a/webkit/appcache/mock_appcache_storage.cc b/webkit/appcache/mock_appcache_storage.cc
index bc4a385..d176288 100644
--- a/webkit/appcache/mock_appcache_storage.cc
+++ b/webkit/appcache/mock_appcache_storage.cc
@@ -187,13 +187,15 @@ void MockAppCacheStorage::ProcessStoreGroupAndNewestCache(
}
AddStoredGroup(group);
- AddStoredCache(newest_cache);
- group->AddCache(newest_cache);
-
- // Copy the collection prior to removal, on final release
- // of a cache the group's collection will change.
- AppCacheGroup::Caches copy = group->old_caches();
- RemoveStoredCaches(copy);
+ if (newest_cache != group->newest_complete_cache()) {
+ AddStoredCache(newest_cache);
+ group->AddCache(newest_cache);
+
+ // Copy the collection prior to removal, on final release
+ // of a cache the group's collection will change.
+ AppCacheGroup::Caches copy = group->old_caches();
+ RemoveStoredCaches(copy);
+ }
if (delegate_ref->delegate)
delegate_ref->delegate->OnGroupAndNewestCacheStored(group, true);
diff --git a/webkit/appcache/mock_appcache_storage.h b/webkit/appcache/mock_appcache_storage.h
index bf70fc6..0337d495 100644
--- a/webkit/appcache/mock_appcache_storage.h
+++ b/webkit/appcache/mock_appcache_storage.h
@@ -163,6 +163,7 @@ class MockAppCacheStorage : public AppCacheStorage {
FRIEND_TEST(MockAppCacheStorageTest, MakeGroupObsolete);
FRIEND_TEST(MockAppCacheStorageTest, StoreNewGroup);
FRIEND_TEST(MockAppCacheStorageTest, StoreExistingGroup);
+ FRIEND_TEST(MockAppCacheStorageTest, StoreExistingGroupExistingCache);
DISALLOW_COPY_AND_ASSIGN(MockAppCacheStorage);
};
diff --git a/webkit/appcache/mock_appcache_storage_unittest.cc b/webkit/appcache/mock_appcache_storage_unittest.cc
index 39fc445..0a0bae5 100644
--- a/webkit/appcache/mock_appcache_storage_unittest.cc
+++ b/webkit/appcache/mock_appcache_storage_unittest.cc
@@ -271,6 +271,48 @@ TEST_F(MockAppCacheStorageTest, StoreExistingGroup) {
EXPECT_EQ(new_cache.get(), group->newest_complete_cache());
}
+TEST_F(MockAppCacheStorageTest, StoreExistingGroupExistingCache) {
+ // Store a group with updates to its existing newest complete cache.
+ MockAppCacheService service;
+ MockAppCacheStorage* storage =
+ reinterpret_cast<MockAppCacheStorage*>(service.storage());
+
+ // Setup some preconditions. Create a group and a complete cache that
+ // appear to be "stored".
+ GURL manifest_url("http://blah");
+ scoped_refptr<AppCacheGroup> group =
+ new AppCacheGroup(&service, manifest_url);
+ int64 cache_id = storage->NewCacheId();
+ scoped_refptr<AppCache> cache = new AppCache(&service, cache_id);
+ cache->set_complete(true);
+ group->AddCache(cache);
+ storage->AddStoredGroup(group);
+ storage->AddStoredCache(cache);
+ // Hold our refs to simulate the UpdateJob holding these refs.
+
+ // Change the group's newest cache.
+ EXPECT_EQ(cache, group->newest_complete_cache());
+ GURL entry_url("http://blah/blah");
+ cache->AddEntry(entry_url, AppCacheEntry(AppCacheEntry::MASTER));
+
+ // Conduct the test.
+ MockStorageDelegate delegate;
+ EXPECT_EQ(size_t(1), storage->stored_caches_.size());
+ EXPECT_EQ(size_t(1), storage->stored_groups_.size());
+ EXPECT_TRUE(storage->IsCacheStored(cache));
+ storage->StoreGroupAndNewestCache(group, cache, &delegate);
+ EXPECT_FALSE(delegate.stored_group_success_);
+ EXPECT_EQ(size_t(1), storage->stored_caches_.size());
+ EXPECT_EQ(size_t(1), storage->stored_groups_.size());
+ MessageLoop::current()->RunAllPending(); // Do async task execution.
+ EXPECT_TRUE(delegate.stored_group_success_);
+ EXPECT_EQ(size_t(1), storage->stored_caches_.size());
+ EXPECT_EQ(size_t(1), storage->stored_groups_.size());
+ EXPECT_TRUE(storage->IsCacheStored(cache));
+ EXPECT_EQ(cache, group->newest_complete_cache());
+ EXPECT_TRUE(cache->GetEntry(entry_url));
+}
+
TEST_F(MockAppCacheStorageTest, MakeGroupObsolete) {
// Make a group obsolete, should complete asyncly.
MockAppCacheService service;