diff options
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/mock_appcache_storage.cc | 16 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_storage.h | 1 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_storage_unittest.cc | 42 |
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; |