diff options
author | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 17:11:05 +0000 |
---|---|---|
committer | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 17:11:05 +0000 |
commit | 43fdd14f0a15825532820cd6b12c233f2fd7be5a (patch) | |
tree | 29672c6892763c08989853392345758e03a84cf7 /webkit/appcache/appcache_host_unittest.cc | |
parent | 46739a21804b7ee71eb8368609e2c3592334bc79 (diff) | |
download | chromium_src-43fdd14f0a15825532820cd6b12c233f2fd7be5a.zip chromium_src-43fdd14f0a15825532820cd6b12c233f2fd7be5a.tar.gz chromium_src-43fdd14f0a15825532820cd6b12c233f2fd7be5a.tar.bz2 |
Implement cancelling an appcache update. An update is cancelled when its application cache group is no longer in use. Refcounting of caches and groups changed to make cancelling an update work.
TEST=updated existing tests, verify deleting group cancels update, verify new refcounting behavior
BUG=none
Review URL: http://codereview.chromium.org/274013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_host_unittest.cc')
-rw-r--r-- | webkit/appcache/appcache_host_unittest.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_host_unittest.cc b/webkit/appcache/appcache_host_unittest.cc index cdfaee2..5e36eef 100644 --- a/webkit/appcache/appcache_host_unittest.cc +++ b/webkit/appcache/appcache_host_unittest.cc @@ -224,6 +224,65 @@ TEST_F(AppCacheHostTest, FailedGroupLoad) { EXPECT_EQ(reinterpret_cast<void*>(1), last_callback_param_); } +TEST_F(AppCacheHostTest, SetSwappableCache) { + AppCacheHost host(1, &mock_frontend_, &service_); + host.SetSwappableCache(NULL); + EXPECT_FALSE(host.swappable_cache_.get()); + + scoped_refptr<AppCacheGroup> group1 = + new AppCacheGroup(&service_, GURL::EmptyGURL()); + host.SetSwappableCache(group1); + EXPECT_FALSE(host.swappable_cache_.get()); + + AppCache* cache1 = new AppCache(&service_, 111); + cache1->set_complete(true); + group1->AddCache(cache1); + host.SetSwappableCache(group1); + EXPECT_EQ(cache1, host.swappable_cache_.get()); + + host.AssociateCache(cache1); + EXPECT_FALSE(host.swappable_cache_.get()); // was same as associated cache + + AppCache* cache2 = new AppCache(&service_, 222); + cache2->set_complete(true); + group1->AddCache(cache2); + EXPECT_EQ(cache2, host.swappable_cache_.get()); // updated to newest + + scoped_refptr<AppCacheGroup> group2 = + new AppCacheGroup(&service_, GURL("http://foo.com")); + AppCache* cache3 = new AppCache(&service_, 333); + cache3->set_complete(true); + group2->AddCache(cache3); + + AppCache* cache4 = new AppCache(&service_, 444); + cache4->set_complete(true); + group2->AddCache(cache4); + EXPECT_EQ(cache2, host.swappable_cache_.get()); // unchanged + + host.AssociateCache(cache3); + EXPECT_EQ(cache4, host.swappable_cache_.get()); // newest cache in group2 + EXPECT_FALSE(group1->HasCache()); // both caches in group1 have refcount 0 + + host.AssociateCache(NULL); + EXPECT_FALSE(host.swappable_cache_.get()); + EXPECT_FALSE(group2->HasCache()); // both caches in group2 have refcount 0 + + // Host adds reference to newest cache when an update is complete. + AppCache* cache5 = new AppCache(&service_, 555); + cache5->set_complete(true); + group2->AddCache(cache5); + host.group_being_updated_ = group2; + host.OnUpdateComplete(group2); + EXPECT_FALSE(host.group_being_updated_); + EXPECT_EQ(cache5, host.swappable_cache_.get()); + + group2->RemoveCache(cache5); + EXPECT_FALSE(group2->HasCache()); + host.group_being_updated_ = group2; + host.OnUpdateComplete(group2); + EXPECT_FALSE(host.group_being_updated_); + EXPECT_FALSE(host.swappable_cache_.get()); // group2 had no newest cache +} // TODO(michaeln): Flesh these tests out more. } // namespace appcache |